Flutter (2.5) - 为 Flutter 提供了启动画面,但已弃用

Flutter (2.5) - A splash screen was provided to Flutter, but this is deprecated

我是 Flutter 的新手,最近尝试使用最新版本的 Flutter 2.5 开发一个测试应用程序来学习。通过在线查看一些教程,我为启动画面添加了 flutter_native_splash: ^1.2.3 包。并且工作正常。

但是,当我第一次启动应用程序时,它显示以下调试消息

W/FlutterActivityAndFragmentDelegate(18569): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.

看完上面link,我不太明白应该做什么。

pubspec.yaml

中的代码
flutter_native_splash:
  color: "#FFFFFF"
  color_dark: "#000000"
  image: assets/images/splash_720.png
  android: true
  ios: true
  android12: true

另外,compileSdkVersion和targetSdkVersion在build.gradle

中设置为31

请帮忙。提前致谢。

要避免该警告,您只需从项目中删除 API 用法。

AndroidManifest.xml 文件中删除这些代码行。

Previously, Android Flutter apps would either set io.flutter.embedding.android.SplashScreenDrawable in their application manifest, or implement provideSplashScreen within their Flutter Activity. This would be shown momentarily in between the time after the Android launch screen is shown and when Flutter has drawn the first frame. This is no longer needed and is deprecated – Flutter now automatically keeps the Android launch screen displayed until Flutter has drawn the first frame. Developers should instead remove the usage of these APIs. - source



更新(颤振 2.8.0)

根据flutter 2.8.0的更新,新建的项目没有这个警告。

他们从 Androidmanifest.yml 中删除了未使用的 API,但仍然有提到的代码。

从 android 清单文件中删除以下行。不再使用

 <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"/>