你会如何在Flutter应用程序中添加启动画面?它应该在任何其他内容之前加载和显示。目前,在Scaffold(home:X)小部件加载之前,会有一个短暂的颜色闪烁。


当前回答

dev已经给出了最好的答案,这不是一个bug,也不是一个问题,只是配置。 花点时间阅读,一切都会迎刃而解。祝大家有愉快的一天。

https://flutter.dev/docs/development/ui/advanced/splash-screen

其他回答

你有多种方法可以做到这一点,但我使用的最简单的方法是:

对于启动图标,我使用颤振库颤振启动图标

对于自定义启动画面,我创建了不同的屏幕分辨率,然后根据Android的分辨率在mipmap文件夹中添加启动图像。

最后是调整Android中res文件夹中drawable文件夹中的launch_background.xml。

只需更改代码如下所示:

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- <item android:drawable="@android:color/white" />
    <item android:drawable="@drawable/<splashfilename>" />     --> -->

    <!-- You can insert your own image assets here -->
    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/<Your splash image name here as per the mipmap folder>"/>
    </item>
</layer-list>

我所见过的少数开发人员将splash添加为可绘制的,我尝试了这一点,但不知为何在Flutter 1.0.0和Dart SDK 2.0+中构建失败。因此,我更喜欢在位图部分添加飞溅。

iOS的飞溅屏幕制作相对简单。

在iOS的Runner文件夹中,只需将LaunchImage.png文件更新为自定义启动画面图像,名称与LaunchImage.png @2x, @3x, @4x相同。

只是一个补充,我觉得在LaunchImage.imageset中有一个4倍的图像很好。只需在Content中更新代码即可。Json与以下行,以下3x规模添加一个4倍规模的选项:

{
      "idiom" : "universal",
      "filename" : "LaunchImage@4x.png",
      "scale" : "4x"
    }

对于Android,转到这个路径,

Android > app > SRC > main > res > drawable > launcher_background.xml

默认代码为白色背景屏幕。 像这样,

<!-- You can insert your own image assets here -->
 <item>
    <bitmap
        android:gravity="center"
        android:src="@mipmap/launch_image" />
</item> 

您可以通过添加图标或任何自定义设计来更改它的颜色或修改它。更多的定制细节签出这为android。


为Ios

在Xcode中打开Ios项目。

选择Runner,然后。内部Runner文件夹Main。故事板文件在那里, 在这里输入图像描述

默认情况下,它的颜色是白色,你可以根据自己的要求自定义或改变颜色,更多的自定义检查这个Ios。

如果有人在应用验证答案后发现图像不存在,请确保您添加的是@mipmap/ic_launcher而不是@mipmap/ic_launcher .png

SplashScreen(
          seconds: 3,
          navigateAfterSeconds: new MyApp(),
          // title: new Text(
          //   'Welcome In SplashScreen',
          //   style: new TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0),
          // ),
          image: new Image.network('https://upload.wikimedia.org/wikipedia/commons/thumb/b/bd/Tesla_Motors.svg/1200px-Tesla_Motors.svg.png'),
          backgroundColor: Colors.white,
          styleTextUnderTheLoader: new TextStyle(),
          photoSize: 150.0,
          loaderColor: Colors.black),
    ),
  );

为安卓 App -> SRC -> main -> res ->drawble->launch_background.xml 和取消 注释块是这样的

<item>
  <bitmap
      android:gravity="center"
      android:src="@mipmap/launch_image" /></item>

有人在这样编码后会出现错误吗 在android studio中使用与系统同步或使缓存无效并重置。这解决了我的问题 在颤振调试模式需要一些时间采取启动画面。构建后,它将减少像本机android