Flutter学习笔记(二)填坑之旅
1.Waiting for another flutter command to release the startup lock…等待另一个flutter命令释放启动锁
1)退出 VS Code。 2)打开 flutter 安装目录 如:…\flutter\flutter\bin\cache 删除里面的 lockfile。 3)重启打开VS Code。
原因:当你的项目异常关闭,下次启动就会出现上面的一行话, 此时需要打开 flutter/bin/cache/lockfile,删除就行了, 或者直接用下面的命令:rm ./flutter/bin/cache/lockfile。
2.MacOS Catalina 10.15.4 ,flutter的命令失效, 提示 zsh: command not found: flutter
1)单次解决办法 这种方法,只对当前终端窗口有效,关闭之后无效了
source ~/.bash_profile
2)永久解决方法 1 、执行:【open ~/.zshrc 】
open ~/.zshrc
2 、如果 提示文件不存在,则执行:【vim ~/.zshrc 】新建一个新文件。
vim ~/.zshrc
3 、再执行【open ~/.bash_profile 】
open ~/.bash_profile
4 、把 bash_profile 中的内容copy到 zshrc 文件中,保存:【:wq回车】。
5 、再使用source命令重新加载一下:【source ~/.zshrc】,下次再编辑这个文件就可以直接执行:【open ~/.zshrc】
source ~/.zshrc
6 、运行【flutter -h 】看生效没有
flutter -h
3.VS Code实现保存时自动代码格式化
实现vs code中代码格式化快捷键:【Shift】+【Alt】+F
实现保存时自动代码格式化:
1)Code - Perference - Settting 点击右上角(Open Setting(JSON) )
2)在settings.json下的【工作区设置】中添加以下语句:
"editor.formatOnType": true,
"editor.formatOnSave": true
4.The named parameter 'colors' isn't defined.
【Ctrl + Shift + P】 on Windows, 【Cmd + Shift + P】 on Macos opens the command palette if you use VS Code.
Then run Dart: Restart Analysis Server.
5.Could not build the application for the simulator. Error launching application on iPhone 12.
flutter clean 也不可以的时候,看看项目中是否引用了**import 'dart:js' **; 删除即可。
6. Unhandled Exception: PlatformException(unregistered_view_type, trying to create a view with an unregistered type, unregistered view type: 'plugins.flutter.io/webview', null)
在info.plist加入
<key>io.flutter.embedded_views_preview</key>
<true/>
7.解决 setState() called after diapose()
网络请求成功前退出了页面,该 State 被从对象树卸载掉,而这时回调了网络请求的方法,方法中带有 setState 的调用,也就导致了该问题。
if (mounted) {
setState(() {
this._books = dataModel.books;
});
}
8.gitignore
git rm -r --cached .
git add .
git commit -am "Remove ignored files"
git pull origin branch-name
git push origin branch-name
9.在中国网络环境下使用 Flutter
Flutter社区主镜像不可以用时,可以用清华大学 TUNA 协会 的源
export PUB_HOSTED_URL=mirrors.tuna.tsinghua.edu.cn/dart-pub
export FLUTTER_STORAGE_BASE_URL=mirrors.tuna.tsinghua.edu.cn/flutter
10.下载镜像特别慢
1)可以直接在githup下载
git clone -b beta github.com/flutter/flu…
2)到这里下载 清华大学开源软件镜像站
11. fatal error: 'Flutter/Flutter.h' file not found
flutter channel master -> stable 之后,项目报错,新建项目可以成功。
解决:把项目中的ios文件夹替换为新建的项目中的文件夹即可。修改修改bundle id 和 info.plist文件。
12.No suitable Android AVD system images are available. You may need to install these using sdkmanager, for example: sdkmanager "system-images;android-27;google_apis_playstore;x86"
解决: 需要 Android Studio 创建虚拟设备而不是VS Code来创建。 打开Android Studio,创建模拟器即可。
转载自:https://juejin.cn/post/6914663169202126856