問(wèn)題一:圖片導(dǎo)入配置后編譯時(shí)報(bào)錯(cuò)
Error detected in pubspec.yaml:
Error on line 48, column 4: Expected a key while parsing a block mapping.
?
48 │ assets:
│ ^
?
Please correct the pubspec.yaml file at /Users/zhanghua/Desktop/learn_flutter/pubspec.yaml
這種問(wèn)題是由于 pubspec.yaml 文件配置不對(duì)導(dǎo)致的螺戳。
錯(cuò)誤配置:flutter 下 assets:
與 uses-material-design: true
層級(jí)結(jié)構(gòu)未對(duì)齊
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/
- assets/images/2.0x/
- assets/images/3.0x/
正確配置:flutter 下 assets:
與 uses-material-design: true
層級(jí)結(jié)構(gòu)對(duì)齊
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/
- assets/images/2.0x/
- assets/images/3.0x/
最后修改 pubspec.yaml 文件配置后醋旦,需要 cd 進(jìn)入 flutter目錄下 執(zhí)行終端命令flutter pub get
,使配置生效。
bogon:learn_flutter zhanghua$ flutter pub get
Running "flutter pub get" in learn_flutter... 1,691ms
問(wèn)題二:圖片導(dǎo)入后圖片資源無(wú)法加載咒劲、查找不到問(wèn)題
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/3.0x/wenhao@3x.png
這種問(wèn)題也是由于 pubspec.yaml 文件圖片路徑配置不對(duì)導(dǎo)致的顷蟆。
配置如圖:
調(diào)用:
Widget build(BuildContext context) {
//圖片路徑
final imageLoc = "assets/images/3.0x/wenhao@3x.png";
return Image(
image:AssetImage(imageLoc),
);
}
如果圖片還是加載不出來(lái)的話 , cd 進(jìn)入 flutter目錄下 執(zhí)行終端命令flutter pub get
,重新運(yùn)行腐魂。
問(wèn)題三:No such module 'Flutter'
在 flutter 新項(xiàng)目做 Swift 混編的時(shí)候 帐偎,打開(kāi)Xcode編譯報(bào)錯(cuò) 如下圖:
如果是在運(yùn)行模擬器時(shí)出現(xiàn) Module '… ’ not found
或者 No such module 'Flutter'
柬讨。您可以事先打開(kāi)您的模擬器奄抽,在Android studio中選擇iphone模擬器先運(yùn)行一次蛔琅,再在Xcode
里面運(yùn)行台谍,可以正常跑通
問(wèn)題四: Error output from Xcode build:
Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
Running Xcode build...
Xcode build done. 8.6s
Failed to build iOS app
Error output from Xcode build:
?
** BUILD FAILED **
**************省略部分********************
Command PhaseScriptExecution failed with a nonzero exit code
note: Using new build system
note: Planning build
note: Constructing build description
Could not build the application for the simulator.
Error launching application on iPhone 11 Pro Max.
解決:
flutter clean
還是出錯(cuò)的話可運(yùn)行:
flutter pub cache repair
最后:flutter clean
問(wèn)題五:Xcode installation is incomplete; a full installation is necessary for iOS development
執(zhí)行命令:
flutter doctor
報(bào)如下錯(cuò)誤:
zhanghua@Breeze chinads_flutter_module % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel master, 2.13.0-0.0.pre.575, on macOS 12.1 21C52 darwin-x64, locale zh-Hans-CN)
[!] Xcode - develop for iOS and macOS
? Xcode installation is incomplete; a full installation is necessary for iOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
[?] Chrome - develop for the web
[?] Android Studio (version 4.1)
[?] VS Code (version 1.66.2)
[?] Connected device (1 available)
解決辦法:
終端中執(zhí)行下面兩行命令
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo gem install cocoapods
再然后執(zhí)行
//1.清除
flutter clean
//2.加載插件
flutter pub get
文章持續(xù)更新中嘁扼、希望對(duì)各位有所幫助树灶、有問(wèn)題可留言 大家共同學(xué)習(xí).