1、修改MainActivity
public class MainActivity extends io.flutter.embedding.android.FlutterActivity如果与flutter有通信,则覆盖下面方法
private final String CHANNEL = "android/back/desktop"; @Override public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { super.configureFlutterEngine(flutterEngine); new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(),CHANNEL) .setMethodCallHandler(((call, result) -> { if (call.method.equals("backDesktop")) { result.success(true); moveTaskToBack(false); } })); }2、修改android/app/src/main/AndroidManifest.xml文件
删除节点 <meta-data android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" android:value="true" />增加节点
<meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/launch_background" /> <!-- Theme to apply as soon as Flutter begins rendering frames --> <meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" /> <meta-data android:name="flutterEmbedding" android:value="2" />3、styles.xml中增加
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar"> <item name="android:windowBackground">@drawable/launch_background</item> </style>4、检查 android/gradle.properties
android.enableJetifier=true android.useAndroidX=true android.enableR8=true5、 检查是否配置成功 flutter clean flutter pub get flutter run