Flutter是一个全新的跨平台开发的语言,我在实际项目开发中也有幸使用到 Flutter 进行完整开发,在这个开发过程当中也是一步步的实验,在这其中也遇到了各类各样的坑, 网上经过各类谷歌,stackoverflow,Flutter官网等查资料,有些问题是解决,但仍是有些问题不能及时解决,因而就本身慢慢的尝试着摸索除了一些解决方案,因此在这里就整理一下分享给你们,跟你们一块儿学习、讨论。android
在项目中使用Flutter Packages get时或命令行执行flutter build 时 会 出现: Waiting for another flutter command to release the startup lock...git
找到\bin\cache中的lockfile文件删除,若是仍是不行则重启IDE从新试下。github
在页面 initState、build、或者页面返回没办法直接使用 context 或 setStateweb
使用bash
Future.delayed(Duration.zero).then((e) {
....
});
复制代码
Build functions must never return null. To return an empty space that causes the building widget to fill available room, return "new Container()". To return an empty space that takes as little room as possible, return "new Container(width: 0.0, height: 0.0)"ide
在 build 方法必须加上super.buildpost
@override
Widget build(BuildContext context) {
super.build(context); //保存状态必须加上
[...]
}
复制代码
post : 发送消息
on : 监听消息
destroy : 销毁
复制代码
错误的使用destory 使得整个应用没办法监听消息学习
在 BaseWidget 的 dispose不能 destory EventManager。EventManager是单例,基类取消就所有取消了。测试
在调起相机、相册选择图片时,点击相机区域、图片选择区域会响应下层 flutter 界面的点击事件ui
目前处理的办法是调起相机、相册时显示一个带蒙层的弹窗,收起相机、机册时取消蒙层弹窗。
在 android 中输入框获焦点,点击两次会闪退。
在IOS须要 配置了io.flutter.embedded_views_preview属性,会致使键盘卡顿。
待官方解决,暂时使用第三方flutter_webview_plugin 插件
flutter_webview_plugin是调用原生 webview.并加到原生主页面上。因此该 webview 是最顶层的,没法在其上显示flutter的视图
要显示弹窗等视图时先判断当前是否有webview页面,而且在进入webview页面时调用FlutterWebviewPlugin().show();退出 webviewd页面时调用FlutterWebviewPlugin().hide();
flutter 关闭弹窗、页面都会都是调用 Navigator.pop(context, result),在这里没办法指定特定的页面路由或弹窗
修改源码把底层的history释放出来,或者尽可能避免这种须要关闭指定页面的作法。
正确的设置了控件的点击事件,点击却没有反应
return GestureDetector(
behavior: HitTestBehavior.translucent,
child: Text("测试${index}"),
onTap: () {},
);
enum HitTestBehavior {
/// Targets that defer to their children receive events within their bounds
/// only if one of their children is hit by the hit test.
deferToChild, //只生效在child的区域好比文字
/// Opaque targets can be hit by hit tests, causing them to both receive
/// events within their bounds and prevent targets visually behind them from
/// also receiving events.
opaque,//GestureDetector的整个区域,不包括它下面的区域
/// Translucent targets both receive events within their bounds and permit
/// targets visually behind them to also receive events.
translucent,// GestureDetector的整个区域以及它下面的区域
}
复制代码
Appbar、Tabbar 默认有固定的高度,如何改变其高度
使用PreferredSize。
若是在使用过程遇到问题,欢迎下方留言交流。