Flutter常见问题解决方案

Waiting for another flutter command to release the startup lock…

打开 flutter/bin/cache/lockfile,删除就行了

或者直接用下面的命令:rm ./flutter/bin/cache/lockfile

Multiple commands produce ‘/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework

  • Option 1: Use the legacy build system . Open ios/Runner.xcworkspace, and change the build system to Legacy Build System.
  • Option 2: Use the new Xcode 10 build system.

    1. Open ios/Runner.xcworkspace
    2. Select the Runner project in the project navigator sidebar.
    3. In the main view, select the Runner target, then select the Build Phases tab.
    4. Expand the Embed Frameworks phase and select Flutter.framework from the embedded frameworks list.
    5. Click - to remove Flutter.framework from the list (be sure to keep App.framework).

使用TabBarView & TabBar遇到一个问题:tab切换的时候,每次都会执行initState

将:

1
2
3
class _demoPageState extends State<LoadImgByLocAppPage> {
...
}

改为

1
2
3
4
5
class _demoPageState extends State<LoadImgByLocAppPage> with AutomaticKeepAliveClientMixin{
...
@override
bool get wantKeepAlive => true;
}

Flutter 升级 flutter upgrade 之后就不能runApp ,异常提示不能下载gradle的pom 文件

  • 检查下 gradle-wrapper.properties 的distributionUrl 跟当前AS使用的gradle版本是否一致。
  • 检查下 /Users/user/flutter/packages/flutter_tools/gradle 文件夹下面的 flutter.gradle文件中的依赖版本是否和当前AS 使用的是否一致。
  • 查看是否开启翻墙 。

Android license status unknown.

  1. 升级 Android Studio
  2. 在SDK Manager 里随便添加一些SDK
  3. sudo chown -R $USER:$USER /opt/*
  4. flutter doctor --android-licenses

可以直接试试第4步。

“Resolving dependencies…”报错,无法正常运行

1.首先打开”/Users/你的用户名/.gradle/“下的”gradle.properties”文件,检查你是否开启过代理,有的话把代理注释掉

2.打开你项目下的”build.gradle”文件,路径是”你的项目/android/“,修改buildscript和allprojects的repositories属性。具体效果图如下图,这一步是为了把下载源替换成阿里的源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
buildscript {
repositories {
// google()
// jcenter()
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}

allprojects {
repositories {
// google()
// jcenter()
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
}
}

3.打开你flutter SDK目录下的”flutter.gradle”,与第二步一样,编辑buildscript下的repositories属性。

image.png

4.重新运行”flutter run”。

如果觉得有帮助就请我喝杯咖啡鼓励我继续创作吧^_^