【问题标题】:Flutter v2.5.0 Android Splash ScreenFlutter v2.5.0 安卓闪屏
【发布时间】:2021-11-07 11:40:32
【问题描述】:

我在当前项目中实现了原生启动画面,自从我升级到 v2.5.0 后一切正常,我开始在控制台上收到此弃用警告:

为 Flutter 提供了启动画面,但已弃用。有关迁移步骤,请参阅 flutter.dev/go/android-splash-migration。

我已经检查了给定的链接(顺便说一句不是很清楚)并告诉我删除 o.flutter.embedding.android.SplashScreenDrawable API,因为颤振现在会自动显示启动画面。

但是在没有代码的情况下运行我的应用程序后,不会出现启动画面,而且启动应用程序需要一段时间 - 可能是在没有启动程序的情况下初始化应用程序。

我这样做是对的还是框架本身的问题?

【问题讨论】:

  • 试试我的回答here希望对你有帮助
  • @RavindraS.Patil 不,它没有:(
  • 我遇到了完全相同的问题,删除“AndroidManifest.xml”中的推荐行后,我的自定义初始屏幕不再显示。我应该在这里做什么?
  • @RavindraS.Patil 不适合我。我已经运行了您建议的命令。谢谢。

标签: android flutter dart splash-screen


【解决方案1】:

这是由于您的 AndroidManifest.xml 中有以下代码导致的,该代码在以前的 Flutter 版本中默认包含:

<meta-data
    android:name="io.flutter.embedding.android.SplashScreenDrawable"
    android:resource="@drawable/launch_background"
/>

解决办法是把上面的代码去掉。

Source

【讨论】:

  • 无法正常工作。删除“AndroidManifest.xml”中的推荐行后,我的自定义初始屏幕不再显示。我应该在这里做什么?
  • 这个解决方案对我有用。
【解决方案2】:

按照这个 youtube 教程,了解如何在 2021 年以正确的方式在 Flutter App 中正确创建启动画面。确保在 android/app/src/main/res 内的 drawable 和 drawable-v21 文件夹中创建 launch_background.xml 文件文件夹。

Create Splash Screen in Flutter App the Right Way in 2021

如果您使用的是 Flutter 2.5,请删除 AndroidManifest.xml 文件中的以下行,因为这里提到的 Flutter 2.5 不再需要它 --> android splash migration

<meta-data
 android:name="io.flutter.embedding.android.SplashScreenDrawable"
 android:resource="@drawable/launch_background"/>

【讨论】:

    【解决方案3】:

    这是一种适用于我的解决方案。

    你在路径“android/app/src/main/res/”上有一个“drawable”和“drawable-v21”文件夹,你必须打开“drawable-v21”文件夹中的“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/your_color" />
    
        <!-- You can insert your own image assets here -->
        <item>
            <bitmap
                android:gravity="center"
                android:src="@drawable/your_image" />
        </item>
    </layer-list>
    

    附:图像应该在“drawable”文件夹中,而不是“drawable-v21”。您可以尝试,但在我的情况下,它不起作用并抛出错误。

    P.S.2 我没有更改“AndroidManifest.xml”、“styles.xml”等文件。

    【讨论】:

      【解决方案4】:

      从您的 AndroidManifest.xml 文件中删除以下行。在较新的版本中不再使用它

      <meta-data
           android:name="io.flutter.embedding.android.NormalTheme"
           android:resource="@style/NormalTheme" />
                  
      <meta-data
            android:name="io.flutter.embedding.android.SplashScreenDrawable"
            android:resource="@drawable/launch_background" />

      【讨论】:

        猜你喜欢
        • 2010-12-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-17
        • 1970-01-01
        • 2018-10-12
        • 2022-10-05
        • 2014-01-09
        相关资源
        最近更新 更多