flutter入坑之路,欢迎交流
关于flutter可以在 flutter官网 看,英文不好的推荐 flutter中文网,特别是里面的flutter for iOS/Android/Web开发者可以帮助我们快速理解flutter的机制。
flutter现在还没有一个稳定的版本,持续更新中,所以经常会在一次更新后,报错,项目不能跑,模拟器闪退之类的,可以先安装老版本的flutter对比下快速排除flutter原因。下面是一些我碰到的flutter报错,记录以分享
1. Running "flutter packages get" in flutter-app...
Because every version of flutter_test from sdk depends on test 1.3.4 and photo_view >=0.0.11 depends on test ^1.5.1, flutter_test from sdk is incompatible withphoto_view >=0.0.11.
$ flutter packages get
Running "flutter packages get" in flutter-app...
Because every version of flutter_test from sdk depends on test 1.3.4 and photo_view >=0.0.11 depends on test ^1.5.1, flutter_test from sdk is incompatible withphoto_view >=0.0.11.
问题原因:flutter更新,导致项目中的依赖老版本的flutter不可用
解决方案:更新flutter,往下走
$ flutter upgrade
Downloading Dart SDK from Flutter engine 6c2ade9fa2b555899530a31cc8cbd1dff3bf5eea...
Unknown operating system. Cannot install Dart SDK
更新flutter之后,又出现这个报错,
问题原因:找不到自己的操作系统去下载,
解决方案:进入flutter\bin
目录下,双击flutter.bat
文件,下载windows/mac需要的系统依赖,
从新回到终端,运行flutter upgrade
$ flutter upgrade
Upgrading Flutter from C:\Users\ZzQ\flutter...
Updating d8cbb8020..d48e6e433
618 files changed, 20519 insertions(+), 6007 deletions(-)
Upgrading engine...
Checking Dart SDK version...
Downloading Dart SDK from Flutter engine 5c8147450db52b81232c138b9f9a65a8f9c61862...
Unzipping Dart SDK...
Building flutter tool...
Running pub upgrade...
Already up-to-date.
Flutter 0.10.2 • channel beta • https://github.com/flutter/flutter.git
Framework • revision d8cbb80206 (4 weeks ago) • 2018-11-20 22:05:23 -0500
Engine • revision 5c8147450d
Tools • Dart 2.1.0-dev.8.0.flutter-bf26f760b1
Running "flutter packages upgrade" in flutter-app... 34.1s
Running flutter doctor...
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.11.9, on Microsoft Windows [Version 10.0.17763.134], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[√] Android Studio (version 3.2)
[√] Connected device (1 available)
• No issues found!
这样就可以正确进入项目中,进行packages依赖拉取了
$ flutter packages get
Running "flutter packages get" in flutter-app... 1.4s
2. Finished with error: FormatException: Bad UTF-8 encoding 0xc3 (at offset 174)
问题原因:Android Studio编码方式,进入file => setting => editor => FileCoding
=> 解决方法:将Global 和Project Encoding 都改成 UTF-8就好
3. 'Flutter/Flutter.h' file not found .
问题原因:Flutter版本更新或者多人协作代码模块更新,已存在的podfile.lock及pod文件夹代码在pod install
后并不能更新,因此在iOS设备运行报错fatal error: 'Flutter/Flutter.h' file not found
=> 解决方法:
1. 删除 podfile.lock
2. 执行 flutter clean 删除build下文件
3. 重新pod install
4. //若以上不行的话尝试更新FlutterSDK
flutter upgrade,(目前我是beta最新版出现问题,切换channel为master最新版后没有出现)
4. Charles 抓不到flutter的包
问题原因:flutter走原生系统代理
=> 解决方法:
//例:192.168.30.241是我本机的localHost
dio.onHttpClientCreate = (HttpClient client){
client.findProxy = (uri) {
return "PROXY 192.168.30.241:8888";
};
};
5. GridView,CustomScrollView 在Column或ListView中不显示,
问题原因:GridView,CustomScrollView都需要指定显示范围,gridView/CustomScrollView包括在Column中无法自由指定显示范围,
=> 解决方法:
- 使用
Expand
包裹,尽可能扩大child范围,或者使用container
指定宽高 - 使用
shrinkWrap = true
属性,官网解释如下:
// 是否应该由正在查看的内容确定scrollDirection中滚动视图的范围。
Whether the extent of the scroll view in the scrollDirection should be determined by the contents being viewed.
Tips:
- flutter受系统影响较大,若是window Ghost系统,建议先激活哦,亲测
网友评论