以下是我学习flutter中遇到的各种问题及解决方法,分享出来以供大家参考~
问题一: Received status code 400 from server: Bad Request
- 原因:Android Studio 的代理设置有误.(有可能是首次安装 Android Studio 的时候,需要设置代理,顺手就填上了)
解决:open /Users/yanan/.gradle
删除类似以下四项.
问题二: Unable to tunnel through proxy
1:修改Gradle版本为本地版本
- 将项目下
Android / Gradle / gradle-wrapper.properties
文件中的distributionUrl
修改为本地存在的gradle版本。- 如:
distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
- 修改为
distributionUrl=file:///E:/Win1064/AndroidStudio/gradle/gradle-5.5.1-all.zip
distributionUrl=file://
为固定写法,后面跟本地gradle所在路径。- 注意,最后路径一定要指向 .zip 压缩包而不是解压后的路径。
2:修改classpath为Android Studio版本
修改项目下的build.gradle
中的classpath :'com.android.tools.build:gradle:3.0.1'
修改自己的Android Studio对应的版本。
如何查看Android Studio版本:通过工具栏中Help选项,选择Check for Updates,在弹出面板点击Configure。
问题三 Could not resolve all artifacts for configuration ‘:classpath’.
buildscript {
repositories {
maven {
url 'https://maven.google.com/'
name 'Google'
}
mavenCentral()
jcenter(){ url 'http://jcenter.bintray.com/'}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.novoda:bintray-release:0.9.1'
classpath 'com.jakewharton:butterknife-gradle-plugin:10.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
mavenCentral()
jcenter(){ url 'http://jcenter.bintray.com/'}
maven { url 'https://jitpack.io' }
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
将jcenter()里面的http换为https即可
buildscript {
repositories {
maven {
url 'https://maven.google.com/'
name 'Google'
}
mavenCentral()
jcenter(){ url 'https://jcenter.bintray.com/'}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.novoda:bintray-release:0.9.1'
classpath 'com.jakewharton:butterknife-gradle-plugin:10.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
mavenCentral()
jcenter(){ url 'https://jcenter.bintray.com/'}
maven { url 'https://jitpack.io' }
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
问题四 ios真机调试
*1.xcode设置中:accounts->
添加自己apple id
*2.创建swift版的flutter create flutter_demo
*3.创建oc版的flutter create -i objc flutter_demo
(该项目生成于项目/ios/文件夹下)
*4.打开ios/Runner.xcworkspace signing&capabilities-> team
添加账号
问题五 fatal: ambiguous argument 'HEAD': unknown revision or path not in the workin
git卸载which -a git
sh /usr/local/git/uninstall.sh
问题六 DioError [DioErrorType.DEFAULT]: FormatException: Unexpected character
这是因为dio请求返回的数据默认是以json的格式读取的,而返回的数据是密文形式,需要修改dio的Options的responseType为ResponseType.plain,这样返回的数据就以字符串形式处理.
Response response = await Dio().get(url, options: new Options(responseType:ResponseType.plain));
问题七 To provide both, use "decoration: BoxDecoration(color: color)".
BoxDecoration.color
不能与Container.color
同时使用,
问题八When the exception was thrown, this was the stack: GridView 或 ListView 嵌套错误
shrinkWrap:true
问题九 GridView 或 ListView 无法滑动(与上层滑动组件冲突)
physics: NeverScrollableScrollPhysics(),
问题十 Missing essential plugin: org.jetbrains.android Please reinstall Android Studio from scratch.
删除 ~/Library/Application Support/Google/AndroidStudioPreview4.1/plugins/disabled_plugin.txt
问题十一 dart Error: Null safety features are disabled for this library.
不支持空安全,移除不支持空安全的包货禁用flutter的空安全支持
问题十二 homebrew:Mac安装brew连接不上解决方法 更换源
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
问题十三 app需要授权时崩溃退出 ios权限申请 添加字段 ios/Runner/Info.plist:
添加相应权限字段到 ios/Runner/Info.plist
问题十四 app提示英文
- xcode找到“info.plist”,添加一项“
Localized resources can be mixed
”,值设置为“yes
”Localization native development region
设置为China
问题十五 无法访问 'https://github.com/ccgus/fmdb.git/':LibreSSL SSL_connect: SSL_ERRO
删除代理即可。
git config --global --list
- 发现其中有 http.https.XXXXXX.proxy 和 https.https.XXXXXX.proxy配置
git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy
问题十六 Another exception was thrown: Null check operator used on a null value
GridView 放在 Column 中 外部需要包裹Expanded()
问题十七 The PrimaryScrollController is currently attached to more than one ScrollPosition.
控制器冲突,需要为每个页面单独制定控制器
final ScrollController _timeScrollController = ScrollController();
SingleChildScrollView(
controller: _timeScrollController,
child: _getTimeList(),
),