当前位置:网站首页>In the release version, the random white screen does not display the content after opening the shutter

In the release version, the random white screen does not display the content after opening the shutter

2022-07-04 21:17:00 SkyCloud5+2

Using the command line

flutter run --release --verbose

It can be on the simulator , simulation release Running status on , Turn off the app process , There is also a log when you open it again

White screen reason :

Flutter To speed up application startup , Not waiting size assignment , Start rendering the interface .

terms of settlement :

monitor window Change in size , When not empty , Again runApp;runApp Must first WidgetsFlutterBinding.ensureInitialized(), Make sure there are WidgetsFlutterBinding example , Otherwise, the screen will be black

Future<void> main() async {

  // If size yes 0, Set callback , In the callback runApp
  if(window.physicalSize.isEmpty){
    print("window size is zero");
    window.onMetricsChanged = (){
      // In the callback ,size It could still be 0
      if(!window.physicalSize.isEmpty){
        window.onMetricsChanged = null;
        print("window onMetricsChanged,run app");
        runMyApp();
      }
    };
  } else{
    // If size Not 0, directly runApp
    print("window load success,run app");
    runMyApp();
  }
}

void runMyApp() async{

  print("window:  ${window.physicalSize.width}  ${window.physicalSize.height}");
  // Ensure that the loading is completed , only runApp
  WidgetsFlutterBinding.ensureInitialized();
  runApp(MyApp());
}

Use window Need to import dart:ui

import 'dart:ui';

原网站

版权声明
本文为[SkyCloud5+2]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207042020466409.html