原生Flutter在安卓端啟動白屏(黑屏)問題

問題及解決后的效果

環境

  • Flutter Channel stable, v1.12.13+hotfix.8
  • Android Studio (version 3.6)

問題

下圖是啟動時黑屏


ori (1).gif

解決后的效果

success (1).gif

解決方法

  1. 第一步
    打開
    android/app/src/main/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" />

    <!-- You can insert your own image assets here -->
    <item>
        <bitmap
            android:src="@mipmap/splash" /> //這一段原來是被注釋掉的,放一張圖片到mipmap-xxhdpi下
    </item>
</layer-list>
image.png
  1. 第二步
    打開android/app/src/main/AndroidManifest.xml


    image.png

    添加綠色方框中的代碼,注意在activity標簽內,代碼可以復制下面的

            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <meta-data
                android:name="io.flutter.embedding.android.SplashScreenDrawable"
                android:resource="@mipmap/splash" />

通過上面兩步應該就可以了

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容