1、右上角debug标识隐藏
MaterialApp
中debugShowCheckedModeBanner
就是控制debug
标识的显示与隐藏的,设置为false
即可;
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter 工程'),
),
body: MyWidget(),
),
);
2、Image部件加载图片问题
使用Image.network('[https://upload-images.jianshu.io/](https://p9-juejin.byteimg.com/)*************')
加载图片,使用Android Studio
运行真机环境(iPhone手机)时工程报错如下:
解决方案:
把手机上使用Android Studio
运行安装的App
删除,然后使用Xcode
运行连接真机运行iOS
工程,要提前配置好证书!运行成功之后(图片能够显示),再次使用Android Studio
运行就正常了;
3、本地图片无法展示问题
1、pubspec.yaml
文件中格式问题
assets:
- images/
这个地方有问题,格式没有对齐,此文件对格式及其严格,assets
要与uses-material-design
对齐,- images/
缩进两个空格;
另外此处路径不要配置错误
2、新加的图片无法显示
项目中原来的图片都能展示,但是新加的图片无法展示,并且报错如下:
Unable to load asset: images/wwww.png
4、Vertical viewport was given unbounded height.
此问题一般是使用ListView
时出现的,报错信息如下:
这是因为我们在添加一个ListView
的时候,需要给ListView
指定高度,此时有两种解决方案,为了便于分析,我们将ListView
放进Container
里边:
- 第一种,使用
Expended
把ListView
包起来,代码及效果如下:
- 第二种,使用
ListView
的shrinkWrap
属性,将其设置为true
,代码及效果如下:
两者结果:使用
Expanded
的方式,ListView
会根据布局自适应剩下的区域;而shrinkWrap
该属性将决定列表的长度是否仅包裹其内容的长度。当ListView嵌在一个无限长的容器组件中时,shrinkWrap必须为true,否则Flutter会给出警告
5、混编:’Flutter/Flutter.h’ file not found
我们使用创建Flutter
工程时生成的原生项目进行混编时,有时候会出现一下两个报错:
解决方案:
rm -rf ios
flutter create -i swift .
将默认生成的iOS工程删除,然后使用上述命令,重新生成原生工程;
6、iOS14+真机Debug运行问题
在iOS14+
之后的真机,运行Futter
项目时可能会报错如下:
On iOS 14+, local network broadcast in apps need to be declared in the app's Info.plist. Debug and profile Flutter apps and modules host VM services on the local network to support debugging features such as hot reload and DevTools. To make your Flutter app or module attachable and debuggable, add a '_dartobservatory._tcp' value to the 'NSBonjourServices' key in your Info.plist for the Debug/Profile configurations. For more information, see https://flutter.dev/docs/development/add-to-app/ios/project-setup#local-network-privacy-permissions
解决方法:
将info.plist
文件复制两份,分别修改名字:
将其路径重新设置:
在info_Debug.plist
文件中添加键NSBonjourServices
,将值设置为_dartobservatory._tcp
- 以下可选:
再次启动项目,将会弹出弹框:
可以通过NSLocalNetworkUsageDescription
来修改显示的信息;
结果如下: