【问题标题】:how to add Splash Screen in flutter如何在颤动中添加启动画面
【发布时间】:2021-04-19 10:28:35
【问题描述】:

我是 Flutter 新手。

我想在我的 Flutter 应用中添加一个启动画面,但我没有找到任何准确的解决方案。

所以,问题是: 如何在 Flutter 中添加启动画面?

【问题讨论】:

  • 您是否正在寻找一种在 Flutter 本身在性能不佳的土豆手机上初始化时显示某些内容的方法?

标签: android flutter dart


【解决方案1】:

在您的flutter项目中,您会找到android文件夹,在该文件夹中,有一个名为Manifest的文件,并且在该清单文件中定义了SplashScreenDrawable,您需要编辑该文件。 (https://i.stack.imgur.com/sfM3Q.png)

将启动标志直接添加到android文件夹中的@drawable/launch_background。

请查找附件。 https://i.stack.imgur.com/es4JO.png[![enter这里有图片描述][1]][1]

【讨论】:

  • 这个答案是最好的,应该首选。但是,如果您能展示一些真实的例子,那就太好了。因为这与颤振无关,并且必须对 android 文件夹做更多的事情。所以新手会觉得很难理解。
  • 谢谢,兄弟成功了! launch_background.xml 有两个文件夹,drawable 和 drawable-v21。所以我在 drawable-v21 中尝试了它的工作。我结帐后发现 drawable-v21 适用于 API 级别高于 21 的手机,可用于更低级别的手机。
【解决方案2】:

制作一个启动画面小部件并将这个小部件设置为初始小部件

class SplashScreen extends StatefulWidget {
      @override
      _SplashScreenState createState() => _SplashScreenState();
    }
    
    class _SplashScreenState extends State<SplashScreen> {
      
    
      @override
      void initState() {
        super.initState();
        new Timer(Duration(milliseconds: 3000), onDoneLoading)
      }
    
      
    
      onDoneLoading() async {
        // SchedulerBinding.instance.addPostFrameCallback((_) {
          Navigator.of(context).pushReplacementNamed('/Signup');
        // });
      }
    
    
    
      @override
      Widget build(BuildContext context) {
        ...Your Widget 
        
      }
    }

【讨论】:

    【解决方案3】:

    您可以查看官方 Flutter documentation 了解更多信息。

    无论如何,您可以使用splashscreen 包在 Flutter 中添加启动画面,如下所示:

    class MySplash extends StatefulWidget {
      @override
      _MySplashState createState() => _MySplashState();
    }
    
    class _MySplashState extends State<MySplash> {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.white,
          body: SplashScreen(
            title: new Text(
              'App Name',
              style: new TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 20.0,
                  fontFamily: 'MyFont'),
            ),
            seconds: 3,
            navigateAfterSeconds: new IntroScreenPage(),
            image: new Image.asset('images/dev.jpg'),
            backgroundColor: Colors.white,
            styleTextUnderTheLoader: new TextStyle(),
            photoSize: 100.0,
            loaderColor: Colors.blue,
            loadingText: Text(
              'Welcome to Flutter',
              style: GoogleFonts.ptSansNarrow(),
            ),
          ),
        );
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-19
      • 2019-01-15
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      • 2018-02-11
      • 1970-01-01
      相关资源
      最近更新 更多