小编Tho*_*asF的帖子

当用户启动App Flutter时获取sharedPreferences

我希望当用户打开应用程序时: 如果它过去已经连接,它会直接打开应用程序,否则如果它刚刚安装它,它会打开一个登录页面

在 Android studio 中我确实喜欢这样:

@Override
    protected void onStart() {
        super.onStart();
        
        SharedPreferencesOpti sp = new SharedPreferencesOpti(this);
        boolean isConnected = sp.getBooleanSharedPreferences("isConnected");
        UserModel.setConnected(isConnected);
        
        if (!UserModel.isConnected())
        {
            Intent intent = new Intent(MainActivity.this, LoginActivity.class);
            startActivity(intent);
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是我的颤振代码:

class MyApp extends StatefulWidget {

  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {


  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter …
Run Code Online (Sandbox Code Playgroud)

sharedpreferences dart flutter

2
推荐指数
1
解决办法
1499
查看次数

如何在 Flutter 中为按钮制作动画

我想问一下,当您点击 Instagram、Tiktok 等图像时,如何为图标的大小设置动画效果...

这是我尝试过的(以及许多其他事情)但没有成功。

 GestureDetector(
              onDoubleTap: (){
                setState(() {
                  _showLikeAnimation = true;
                  _sizeFavoriteAnimation = 60.0; //old value is 20.0
                });
              },
              child: Stack(
                alignment: AlignmentDirectional.center,
                children: [
                  _imagePost(),
                  AnimatedSize(curve: Curves.easeIn, duration: const Duration(seconds: 2), child: Icon(Icons.favorite, size: _sizeFavoriteAnimation))
                ],
              )),
Run Code Online (Sandbox Code Playgroud)

你有什么想法吗?

dart flutter

0
推荐指数
1
解决办法
3916
查看次数

标签 统计

dart ×2

flutter ×2

sharedpreferences ×1