flutter入坑之路,歡迎交流
關(guān)于flutter可以在 flutter官網(wǎng) 看,英文不好的推薦 flutter中文網(wǎng)娩鹉,特別是里面的flutter for iOS/Android/Web開發(fā)者可以幫助我們快速理解flutter的機(jī)制。
flutter現(xiàn)在還沒有一個(gè)穩(wěn)定的版本,持續(xù)更新中到推,所以經(jīng)常會(huì)在一次更新后,報(bào)錯(cuò)惕澎,項(xiàng)目不能跑莉测,模擬器閃退之類的,可以先安裝老版本的flutter對(duì)比下快速排除flutter原因唧喉。下面是一些我碰到的flutter報(bào)錯(cuò)捣卤,記錄以分享
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更新,導(dǎo)致項(xiàng)目中的依賴?yán)习姹镜膄lutter不可用
解決方案:更新flutter八孝,往下走
$ flutter upgrade
Downloading Dart SDK from Flutter engine 6c2ade9fa2b555899530a31cc8cbd1dff3bf5eea...
Unknown operating system. Cannot install Dart SDK
更新flutter之后董朝,又出現(xiàn)這個(gè)報(bào)錯(cuò),
問題原因:找不到自己的操作系統(tǒng)去下載干跛,
解決方案:進(jìn)入flutter\bin
目錄下子姜,雙擊flutter.bat
文件,下載windows/mac需要的系統(tǒng)依賴楼入,
從新回到終端哥捕,運(yùn)行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!
這樣就可以正確進(jìn)入項(xiàng)目中牧抽,進(jìn)行packages依賴?yán)×?/p>
$ 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編碼方式,進(jìn)入file => setting => editor => FileCoding
=> 解決方法:將Global 和Project Encoding 都改成 UTF-8就好
3. 'Flutter/Flutter.h' file not found .
問題原因:Flutter版本更新或者多人協(xié)作代碼模塊更新遥赚,已存在的podfile.lock及pod文件夾代碼在pod install
后并不能更新扬舒,因此在iOS設(shè)備運(yùn)行報(bào)錯(cuò)fatal error: 'Flutter/Flutter.h' file not found
=> 解決方法:
1. 刪除 podfile.lock
2. 執(zhí)行 flutter clean 刪除build下文件
3. 重新pod install
4. //若以上不行的話嘗試更新FlutterSDK
flutter upgrade,(目前我是beta最新版出現(xiàn)問題,切換channel為master最新版后沒有出現(xiàn))
4. Charles 抓不到flutter的包
問題原因:flutter走原生系統(tǒng)代理
=> 解決方法:
//例:192.168.30.241是我本機(jī)的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
包裹愧薛,盡可能擴(kuò)大child范圍晨炕,或者使用container
指定寬高 - 使用
shrinkWrap = true
屬性,官網(wǎng)解釋如下:
// 是否應(yīng)該由正在查看的內(nèi)容確定scrollDirection中滾動(dòng)視圖的范圍毫炉。
Whether the extent of the scroll view in the scrollDirection should be determined by the contents being viewed.
Tips:
- flutter受系統(tǒng)影響較大府瞄,若是window Ghost系統(tǒng),建議先激活哦碘箍,親測