Flutter android release 模式灰屏,即使没有错误,debug 模式也红屏
Flutter android grey screen in release mode even if there are no errors or red screens in debug mode
我在 android 真实设备上的初始屏幕后启动时出现灰屏。我已经解决了所有错误或红屏问题,然后再次尝试,但还是一样。
注意:在这个应用商店之前,我已经发布了这个应用程序的 2 个版本。所以这不是第一个了。
我的日志
Flutter run key commands.
h Repeat this help message.
c Clear the screen
q Quit (terminate the application on the device).
I/flutter (24661): <-- stops here nothing after this
有时它在调试模式下运行良好,但在发布模式下不 工作。您可以通过终端中的 运行 下面的命令捕获该错误。
flutter run --release
命令编译为发布模式。当灰屏发生时,您可以检查您的调试控制台。
我没有任何效果,因为 UI 中没有错误。错误出现在主应用程序的开头。在 Firebase.initializeApp();
之前添加 await
之后就像奇迹一样。
void main() async {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.transparent));
**await** Firebase.initializeApp(); //adding await solved the problem
SharedPreferences.getInstance().then((prefs) {
var brightness = SchedulerBinding.instance.window.platformBrightness;
if (brightness == Brightness.dark) {
prefs.setBool('darkMode', true);
} else {}
var darkModeOn = prefs.getBool('darkMode') ?? false;
runApp(
ChangeNotifierProvider<ThemeNotifier>(
create: (_) => ThemeNotifier(darkModeOn ? darkTheme : lightTheme),
child: MaterialApp(
home: root(),
),
),
);
});
}
我在 android 真实设备上的初始屏幕后启动时出现灰屏。我已经解决了所有错误或红屏问题,然后再次尝试,但还是一样。
注意:在这个应用商店之前,我已经发布了这个应用程序的 2 个版本。所以这不是第一个了。
我的日志
Flutter run key commands.
h Repeat this help message.
c Clear the screen
q Quit (terminate the application on the device).
I/flutter (24661): <-- stops here nothing after this
有时它在调试模式下运行良好,但在发布模式下不 工作。您可以通过终端中的 运行 下面的命令捕获该错误。
flutter run --release
命令编译为发布模式。当灰屏发生时,您可以检查您的调试控制台。
我没有任何效果,因为 UI 中没有错误。错误出现在主应用程序的开头。在 Firebase.initializeApp();
之前添加 await
之后就像奇迹一样。
void main() async {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.transparent));
**await** Firebase.initializeApp(); //adding await solved the problem
SharedPreferences.getInstance().then((prefs) {
var brightness = SchedulerBinding.instance.window.platformBrightness;
if (brightness == Brightness.dark) {
prefs.setBool('darkMode', true);
} else {}
var darkModeOn = prefs.getBool('darkMode') ?? false;
runApp(
ChangeNotifierProvider<ThemeNotifier>(
create: (_) => ThemeNotifier(darkModeOn ? darkTheme : lightTheme),
child: MaterialApp(
home: root(),
),
),
);
});
}