当前位置:网站首页>Flutter在 release版本,打开后随机白屏不显示内容
Flutter在 release版本,打开后随机白屏不显示内容
2022-07-04 20:20:00 【SkyCloud5+2】
使用命令行
flutter run --release --verbose可以在模拟器上,模拟release上的运行状态,关掉app进程,再打开也有日志
白屏原因:
Flutter为加快应用启动速度,未等size赋值,就开始渲染界面。
解决办法:
监听window的尺寸变化,当不为空时,再runApp;runApp必须先WidgetsFlutterBinding.ensureInitialized(),确保有WidgetsFlutterBinding实例,不然会黑屏
Future<void> main() async {
//如果size是0,则设置回调,在回调中runApp
if(window.physicalSize.isEmpty){
print("window size is zero");
window.onMetricsChanged = (){
//在回调中,size仍然有可能是0
if(!window.physicalSize.isEmpty){
window.onMetricsChanged = null;
print("window onMetricsChanged,run app");
runMyApp();
}
};
} else{
//如果size非0,则直接runApp
print("window load success,run app");
runMyApp();
}
}
void runMyApp() async{
print("window: ${window.physicalSize.width} ${window.physicalSize.height}");
//需确保加载完成,才runApp
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}使用window需导入 dart:ui
import 'dart:ui';边栏推荐
- Advantages of semantic tags and block level inline elements
- Summary of the mistakes in the use of qpainter in QT gobang man-machine game
- 偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
- Render function and virtual DOM
- Huawei simulator ENSP common commands
- LeetCode 8. 字符串转换整数 (atoi)
- 基于OpenCV haarcascades的对象检测
- Leetcode+ 81 - 85 monotone stack topic
- 华为ensp模拟器 给路由器配置DHCP
- 阿里云国际版CDN的优势
猜你喜欢

数十亿公民信息遭泄漏!公有云上的数据安全还有“救”吗?

PS vertical English and digital text how to change direction (vertical display)

shp数据制作3DTiles白膜

Pytorch---使用Pytorch实现LinkNet进行语义分割

Leetcode+ 81 - 85 monotone stack topic

PS竖排英文和数字文字怎么改变方向(变竖直显示)

Introduction to pressure measurement of JMeter

From automation to digital twins, what can Tupo do?

黄金k线图中的三角形有几种?

【服务器数据恢复】某品牌服务器存储raid5数据恢复案例
随机推荐
Sword finger offer II 80-100 (continuous update)
Huawei ENSP simulator realizes communication security (switch)
Idea case shortcut
2021 CCPC 哈尔滨 I. Power and Zero(二进制 + 思维)
伦敦银走势图分析的新方法
Go notes (1) go language introduction and characteristics
Nmap scan
See how Tencent does interface automation testing
hash 表的概念及应用
Google colab踩坑
Automatic generation of interface automatic test cases by actual operation
宝塔 7.9.2 宝塔控制面板绕过 手机绑定认证 绕过官方认证
From automation to digital twins, what can Tupo do?
[server data recovery] a case of RAID5 data recovery stored in a brand of server
Huawei simulator ENSP common commands
杰理之AD 系列 MIDI 功能说明【篇】
杰理之AD 系列 MIDI 功能说明【篇】
GVM use
偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
[Shenbo introduction] VI How to contact your favorite doctoral tutor