问题一:图片导入配置后编译时报错
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
这种问题是由于 pubspec.yaml 文件配置不对导致的。
错误配置:flutter 下 assets:
与 uses-material-design: true
层级结构未对齐
# 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
层级结构对齐
# 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 进入 flutter目录下 执行终端命令flutter pub get
,使配置生效。
bogon:learn_flutter zhanghua$ flutter pub get
Running "flutter pub get" in learn_flutter... 1,691ms
问题二:图片导入后图片资源无法加载、查找不到问题
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/3.0x/wenhao@3x.png
这种问题也是由于 pubspec.yaml 文件图片路径配置不对导致的。
配置如图:
![](https://img.haomeiwen.com/i3626918/ad6acebf1715f06c.png)
调用:
Widget build(BuildContext context) {
//图片路径
final imageLoc = "assets/images/3.0x/wenhao@3x.png";
return Image(
image:AssetImage(imageLoc),
);
}
如果图片还是加载不出来的话 , cd 进入 flutter目录下 执行终端命令flutter pub get
,重新运行。
问题三:No such module 'Flutter'
在 flutter 新项目做 Swift 混编的时候 ,打开Xcode编译报错 如下图:
![](https://img.haomeiwen.com/i3626918/6d67aa30f632f488.png)
如果是在运行模拟器时出现 Module '… ’ not found
或者 No such module 'Flutter'
。您可以事先打开您的模拟器,在Android studio中选择iphone模拟器先运行一次,再在Xcode
里面运行,可以正常跑通
问题四: 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
还是出错的话可运行:
flutter pub cache repair
最后:flutter clean
问题五:Xcode installation is incomplete; a full installation is necessary for iOS development
执行命令:
flutter doctor
报如下错误:
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)
解决办法:
终端中执行下面两行命令
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo gem install cocoapods
再然后执行
//1.清除
flutter clean
//2.加载插件
flutter pub get
文章持续更新中、希望对各位有所帮助、有问题可留言 大家共同学习.
网友评论