1、右上角debug标识隐藏

MaterialAppdebugShowCheckedModeBanner就是控制debug标识的显示与隐藏的,设置为false即可;

  1. MaterialApp(
  2. debugShowCheckedModeBanner: false,
  3. home: Scaffold(
  4. appBar: AppBar(
  5. title: const Text('Flutter 工程'),
  6. ),
  7. body: MyWidget(),
  8. ),
  9. );

2、Image部件加载图片问题

使用Image.network('[https://upload-images.jianshu.io/](https://p9-juejin.byteimg.com/)*************')加载图片,使用Android Studio运行真机环境(iPhone手机)时工程报错如下:
image.png
解决方案:
把手机上使用Android Studio运行安装的App删除,然后使用Xcode运行连接真机运行iOS工程,要提前配置好证书!运行成功之后(图片能够显示),再次使用Android Studio运行就正常了;

3、本地图片无法展示问题

1、pubspec.yaml文件中格式问题

  1. assets:
  2. - images/

这个地方有问题,格式没有对齐,此文件对格式及其严格,assets要与uses-material-design对齐,- images/缩进两个空格;
另外此处路径不要配置错误

2、新加的图片无法显示

项目中原来的图片都能展示,但是新加的图片无法展示,并且报错如下:

  1. Unable to load asset: images/wwww.png

将模拟器或者真机上的App卸载,重新运行工程,安装App

4、Vertical viewport was given unbounded height.

此问题一般是使用ListView时出现的,报错信息如下:
image.png
这是因为我们在添加一个ListView的时候,需要给ListView指定高度,此时有两种解决方案,为了便于分析,我们将ListView放进Container里边:

  • 第一种,使用ExpendedListView包起来,代码及效果如下:

image.png

  • 第二种,使用ListViewshrinkWrap属性,将其设置为true,代码及效果如下:

image.png

两者结果:使用Expanded的方式,ListView会根据布局自适应剩下的区域;而shrinkWrap该属性将决定列表的长度是否仅包裹其内容的长度。当ListView嵌在一个无限长的容器组件中时,shrinkWrap必须为true,否则Flutter会给出警告

5、混编:’Flutter/Flutter.h’ file not found

我们使用创建Flutter工程时生成的原生项目进行混编时,有时候会出现一下两个报错:
image.png
image.png
解决方案:

  1. rm -rf ios
  2. flutter create -i swift .

将默认生成的iOS工程删除,然后使用上述命令,重新生成原生工程;

6、iOS14+真机Debug运行问题

iOS14+之后的真机,运行Futter项目时可能会报错如下:

  1. 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文件复制两份,分别修改名字:
image.png
将其路径重新设置:
image.png
info_Debug.plist文件中添加键NSBonjourServices,将值设置为_dartobservatory._tcp
image.png

  • 以下可选:

再次启动项目,将会弹出弹框:
image.png
可以通过NSLocalNetworkUsageDescription来修改显示的信息;
image.png
结果如下:
image.png