flutter - 在第一个运行的应用程序中颤动显示黑屏
问题描述
这个参考不能解决我的问题
切换到颤振通道master
并升级颤振后,这个问题在我的应用程序上没有解决。我该如何解决?
flutter doctor -v
[√] Flutter (Channel master, 1.22.0-10.0.pre.139, on Microsoft Windows [Version 10.0.19041.450], locale en-US)
• Flutter version 1.22.0-10.0.pre.139 at F:\software\flutter
• Framework revision 3dfbdac6f4 (3 hours ago), 2020-09-11 11:40:03 -0400
• Engine revision 983b0ef164
• Dart version 2.10.0 (build 2.10.0-116.0.dev)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
• Android SDK at F:\software\sdk
• Platform android-30, build-tools 30.0.0
• ANDROID_HOME = F:\software\sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] Android Studio (version 4.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 49.0.2
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] Connected device (1 available)
• WAS LX1A (mobile) • 2XJDU17C14006203 • android-arm64 • Android 8.0.0 (API 26)
新的flutter应用内容:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
安卓style.xml
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">@android:color/white</item>
</style>
</resources>
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:gravity="center"
android:src="@mipmap/ic_launcher" />
</item>
</layer-list>
AndroidManifest.xml
<application
android:name="io.flutter.app.FlutterApplication"
android:label="instaluxury"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
</application>
解决方案
这个问题出现在所有flutter
构建版本上,关于这个问题,我们的问题通过这段代码解决了:
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivityLaunchConfigs
import io.flutter.embedding.android.FlutterActivityLaunchConfigs.BackgroundMode
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterFragmentActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
override fun getBackgroundMode(): FlutterActivityLaunchConfigs.BackgroundMode {
return BackgroundMode.transparent
}
}
推荐阅读
- javascript - 在完成 for 循环之前 Promise 拒绝
- django - 基于尚未加载的数据的模型中的Django默认值
- python - pandas cumsum gt 结果分配回原始数据帧
- php - 如果只打印,我是否需要对表格进行消毒?
- typescript - 有没有办法在没有显式类型的情况下使用泛型类型?
- java - 从无限循环中读取流
- c++ - 在 std::thread 或 pthread_create 中创建的 QObject 的 QThreadData 是什么
- ios - 如何通过协调器模式将值从第二个视图控制器传递到第一个视图控制器
- python - 如何改进我的 CNN?高且持续的验证错误
- powershell - 在 Powershell 的条件语句中使用时间