Deprecated Splash Screen API Migration
Prior to Flutter 2.5, Flutter apps could add a splash screen by defining it within the metadata of their application manifest file (AndroidManifest.xml), by implementing provideSplashScreen within their FlutterActivity, or both. This would display momentarily in between the time after the Android launch screen is shown and when Flutter has drawn the first frame. This approach is now deprecated as of Flutter 2.5. Flutter now automatically keeps the Android launch screen displayed until it draws the first frame.
To migrate from defining a custom splash screen to just defining a custom launch screen for your application, follow the steps that correspond to how your application's custom splash screen was defined prior to the 2.5 release.
Custom splash screen defined in FlutterActivity
Locate your application's implementation of
provideSplashScreen()within itsFlutterActivityand delete it. This implementation should involve the construction of your application's custom splash screen as aDrawable. For example:java@Override public SplashScreen provideSplashScreen() { // ... return new DrawableSplashScreen( new SomeDrawable( ContextCompat.getDrawable(this, R.some_splash_screen))); }Use the steps in the section directly following to ensure that your
Drawablesplash screen (R.some_splash_screenin the previous example) is properly configured as your application's custom launch screen.
Custom splash screen defined in Manifest
Locate your application's
AndroidManifest.xmlfile. Within this file, find theactivityelement. Within this element, identify theandroid:themeattribute and themeta-dataelement that defines a splash screen as anio.flutter.embedding.android.SplashScreenDrawable, and update it. For example:xml<activity // ... android:theme="@style/SomeTheme"> // ... <meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/some_splash_screen" /> </activity>If the
android:themeattribute isn't specified, add the attribute and define a launch theme for your application's launch screen.Delete the
meta-dataelement, as Flutter no longer uses that, but it can cause a crash.Locate the definition of the theme specified by the
android:themeattribute within your application'sstyleresources. This theme specifies the launch theme of your application. Ensure that thestyleattribute configures theandroid:windowBackgroundattribute with your custom splash screen. For example:xml<resources> <style name="SomeTheme" // ... > <!-- Show a splash screen on the activity. Automatically removed when Flutter draws its first frame --> <item name="android:windowBackground">@drawable/some_splash_screen</item> </style> </resources>
除非另有说明,否则本网站上的文档反映的是 Flutter 的最新稳定版本。页面最后更新于 2025-01-30。 查看源代码 或 报告问题。