当前位置:网站首页>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';边栏推荐
- Introduction to pressure measurement of JMeter
- [solution] paddlepaddle 2 X call static graph mode
- 杰理之AD 系列 MIDI 功能说明【篇】
- vim异步问题
- 插入排序,选择排序,冒泡排序
- Implementation of redis distributed lock
- Huawei ENSP simulator layer 3 switch
- Poster cover of glacier
- PermissionError: [Errno 13] Permission denied: ‘data.csv‘
- 华为ensp模拟器 DNS服务器的配置
猜你喜欢

MySQL --- 数据库查询 - 聚合函数的使用、聚合查询、分组查询

Y56. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (29)

LeetCode+ 81 - 85 单调栈专题

NetWare r7000 Merlin system virtual memory creation failed, prompting that the USB disk reading and writing speed does not meet the requirements. Solution, is it necessary to create virtual memory??

c语言函数形参自增自减情况分析
![[1200. Minimum absolute difference]](/img/fa/4ffbedd8f24c75a20d3eaeaf0430ae.png)
[1200. Minimum absolute difference]

杰理之增加进关机前把触摸模块关闭流程【篇】

【1200. 最小绝对差】

Idea configuration standard notes

黄金k线图中的三角形有几种?
随机推荐
Sword finger offer II 80-100 (continuous update)
2021 CCPC 哈尔滨 B. Magical Subsequence(思维题)
Detailed explanation of multi-mode input event distribution mechanism
nmap扫描
ApplicationContext 与 BeanFactory 区别(MS)
LeetCode 8. 字符串转换整数 (atoi)
[micro service SCG] use of predict
杰理之增加进关机前把触摸模块关闭流程【篇】
Idea case shortcut
hash 表的概念及应用
Implementation of redis distributed lock
NetWare r7000 Merlin system virtual memory creation failed, prompting that the USB disk reading and writing speed does not meet the requirements. Solution, is it necessary to create virtual memory??
6月“墨力原创作者计划”获奖名单公布!邀您共话国产数据库
网络命名空间
杰理之AD 系列 MIDI 功能说明【篇】
colResizable.js自动调整表格宽度插件
GVM use
Huawei ENSP simulator configures DHCP for router
杰理之AD 系列 MIDI 功能说明【篇】
Browser render page pass