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 |
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系博为峰小编(021-64471599-8017),我们将立即处理