目录
1.1 安卓release包缺少libflutter.so
1.2 AndroidStudio导入项目后自动变为model,没有Flutter目录
1.3 输入框内容为空时,长按不显示粘贴工具栏
1.4 SWIFT_VERSION '5.0' is unsupported, supported versions are: 3.0, 4.0, 4.2
1.5 复制粘贴面板英文的问题
1.6 调用库的时候报Methods marked with @UiThread must be executed on the main thread.Current thread: XXXX
1.7 用Navigator.of(context).pushNamed(routeName)如何传递参数
1.8 监听NestedScrollView中body属性里的widget滚动事件
1.9 使用FutureBuilder每调用一次setState就会重新请求future
1.10 IOS上出现cutButtonLabel was called on null
1.11 IOS上打包后出现could not create Dart VM
1.12 SliverList里的内容无法定位
1.13 添加WillPopScope之后,IOS的滑动返回效果失效
1.14 ios端运行报错<Flutter/Flutter.h> not found
1.15 发布Flutter插件时出现Failed to upload the package \n pub finished with exit code 1
1.16 慎用GlobalKey,拿取currentState时有一个for循环,页面多时会出现卡顿
1.17 环境搭建过程中,Android真机无法连接上
1.18 打包上传IOS时出现does not support the minimum OS Version specified in the Info.plist.
1.19 使用Provider过程中,使用Selector当数据更改时无法自动重绘
1.1 安卓release包缺少libflutter.so
修改/android/app/build.gradle文件如下
android{
defaultConfig{
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
buildTypes {
debug {
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
release {
ndk {
abiFilters "armeabi-v7a"
}
}
}
}
1.2 AndroidStudio导入项目后自动变为model,没有Flutter目录

解决方法:
在导入项目时选择下面选项
File-Open-选中你的项目
1.3 输入框内容为空时,长按不显示粘贴工具栏
将输入框中的autoFocus属性为ture去掉
1.4 SWIFT_VERSION '5.0' is unsupported, supported versions are: 3.0, 4.0, 4.2
将项目打开为ios项目,然后在文件列面中找到Pods(建议升级xcode即可解决)

1.5 复制粘贴面板英文的问题
在pubspec.yaml添加国际化支持,然后运行flutter packages get
dependencies:
...
flutter_localizations:
sdk: flutter
找到代码MaterialApp或者CupertinoApp或者WidgetsApp的文件,添加下面代码即可
MaterialApp(
//...
//new
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
supportedLocales:[
Locale('zh',''),
Locale('en','')
],
//new
)
1.6 调用库的时候报Methods marked with @UiThread must be executed on the main thread.Current thread: XXXX
出现该异常的主要原因是Flutter1.7.8版本添加了线程安全,需要原生在主线程中返回给Flutter
解决方法:
- 库的问题?
到pub库中找到最新的版本,更改最新的版本,然后运行flutter packages get - 自己写的库问题?
假如:
//Result result flutter的result
new Thread(new Runnable() {
public void run() {
//.....
result.success(null);//这里就会导致异常
}).start();
改为
//Result result flutter的result
new Thread(new Runnable() {
public void run() {
//.....
new Handler().post(new Runnable() {
@Override
public void run() {
result.success(file.getAbsolutePath());
}
});
}).start();
上面是伪代码,不建议这样做,可能会导致内存溢出
1.7 用Navigator.of(context).pushNamed(routeName)如何传递参数
传递参数
Navigator.of(context).pushNamed(routeName,arguments:{
“name":"我是参数"
})
获取参数
final arguments=ModalRoute.of(context).settings.arguments;
1.8 监听NestedScrollView中body属性里的widget滚动事件
这个只要在对应的body里嵌套NotificationListener即可
NestedScrollView(
// controller: scrollController,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return [
//....
];
},
body: Builder(
builder: (BuildContext context) => NotificationListener<ScrollNotification>(
onNotification: onNotification,//你要的监听
child: CustomScrollView(
slivers: <Widget>[
//....
],
),
),
)
1.9 使用FutureBuilder每调用一次setState就会重新请求future
解决方法:将future提取出来,作为一个变量
Future<int> future;
@override
void initState() {
super.initState();
future=getInt();
}
FutureBuilder<int>(
future: future,
builder: (context, snapshot) {
return ...;
}
),
Future<int> getInt(){
return Future.value(1);
}
1.10 IOS上出现cutButtonLabel was called on null
解决方法:添加GlobalCupertinoLocalizations.delegate
MaterialApp(
//...
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
//new
GlobalCupertinoLocalizations.delegate,
//new
],
supportedLocales: [
const Locale('zh', 'CH'),
const Locale('en', 'US'),
],
locale: const Locale('zh'),
//...
)
1.11 IOS上打包后出现could not create Dart VM
因为你没有生成flutter_assets相关文件,所以导致Dart代码没有打进包里
解决方法:在打包前运行一下命令,生成的文件不用管,继续你的操作
flutter build ios --release
1.12 SliverList里的内容无法定位
将需要定位的内容单独移出来即可
1.13 添加WillPopScope之后,IOS的滑动返回效果失效
将WillPopScope去掉即可
1.14 ios端运行报错<Flutter/Flutter.h> not found
将/ios/Podfile.lock 文件删除后到ios目录下重新运行命令pod install即可
1.15 发布Flutter插件时出现Failed to upload the package \n pub finished with exit code 1
因为你设置了PUB_HOSTED_URL导致上传到了其他的pub仓库中,dart主要的仓库地址为https://pub.dev只要设置成为该地址即可

1.17 环境搭建过程中,Android真机无法连接上
tools文件夹找不到?
到官网下载

- 然后把它放到
Android SDK的目录下 - 配置环境变量,然后运行
sdkmanager --update - 发现如果找不到
Java需要先配置Java环境 - 运行成功后,再执行
sdkmanager --licenses,一直点y,即可 - 运行完成后,如果执行
flutter doctor -v看到Android Studio下都是对的,表示成功
1.18 打包上传IOS时出现does not support the minimum OS Version specified in the Info.plist.
修改项目/ios/Flutter/AppFrameworkInfo.plist的
<key>MinimumOSVersion</key>
<string>8.0</string>
改为
<key>MinimumOSVersion</key>
<string>9.0</string>
1.19 使用Provider过程中,使用Selector当数据更改时无法自动重绘
当选择的是一个Map或者List的时候,需要注意,不能把源对象传递过去
Selector<MyProvider, Map<String, dynamic>>(
//watch start
selector: (BuildContext context, MyProvider provider) =>
Map.from(provider.map),
//watch end
shouldRebuild: widget.shouldRebuild,
builder: (BuildContext context, Map<String, dynamic> value,
Widget child) =>
widget.builder(value),
)
欢迎在评论区留下你的bug问题,在线
修bug写