前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Flutter 遇到的坑

Flutter 遇到的坑

作者头像
Yif
发布2019-12-26 14:58:40
1.6K0
发布2019-12-26 14:58:40
举报
文章被收录于专栏:Android 进阶Android 进阶
undefined
undefined
  1. Flutter Error: Navigator operation requested with a context that does not include a Navigator

解决办法:不能直接在new MaterialApp中调用Navigator.of(context).push()

  1. RefreshIndicator在ListView条目较少时不触发下拉刷新 RefreshIndicator是根据下拉时的偏移量触发刷新,当条目较少时(未占满一个屏幕),ListView不能滚动,所以无法触发下拉刷新,给ListView的physice属性设置值为new AlwaysScrollableScrollPhysics(),让ListView在任何情况下都可以滑动,也就可以触发RefreshIndicator的刷新。
代码语言:javascript
复制
Widget listView = new ListView.builder
( //注意这里physics 
physics: new AlwaysScrollableScrollPhysics(),
itemCount: listData.length, 
itemBuilder: (context, i) => buildItem(i),
 controller: _contraller,
 );
代码语言:javascript
复制
TarBarView每次切换时其条目Widget都会执行initState()
 在其条目Widget的xxxState方法扩展AutomaticKeepAliveClientMixin,并返回true
 慎用!!!如果大于等于3个tab,这个有bug,最好不用
 当前tab切到任意非相邻tab(如:第一个tab切换到第三个),会报错

class ArticleListPageState extends State<ArticleListPage>  
  with AutomaticKeepAliveClientMixin {  
//  with AutomaticKeepAliveClientMixin 并且get wantKeepAlive返回        true,tab切换时,不会每次执行initState 
@override
bool get wantKeepAlive => true; }
  1. Flutter 图片资源加载失败unable to load image/assets 需要在项目中的pubspec.yaml中进行配置assets,将images文件下的图片都加到此位置
img
img
  1. info: This class inherits from a class marked as @immutable, and therefore should be immutable (all instance fields must be final). 在StatelessWidget或者StatefulWidget类中的参数必须使用final定义,否则Dart Analysis会报warning,因为StatelessWidget是不可变的,StatefulWidget实例本身是不可变的,并将其可变状态存储在由createState方法创建的单独State对象中,或者存储在该State所订阅的对象中,例如StreamChangeNotifier对象,其引用存储在StatefulWidget的最终字段中。
  2. info: Name non-constant identifiers using lowerCamelCase.  使用小写字母进行命名变量,否则会报这个warning,例如:feedUrl 或者是 title
  3. Flutter 打包报错 Execution failed for task ':app:validateSigningRelease'.Keystore file '/Users/zhangtianzhu/Downloads/GankFlutter-master/android/app/</Users/zhangtianzhu/key.jks>' not found for signing config 'release'. 解决办法: You must remove the '<' chars, it's only as sample data. storePassword=yourpasswordhere keyPassword=yourkeypasswordhere keyAlias=youralias storeFile=/your/path/key.jks
代码语言:javascript
复制
【flutter 溢出BUG】 bottom overflowed by 104 PIXELS
 一开始直接使用Scaffold布局,body:new Column 然后结果调出键盘的时候就报这个错了
 解决办法是使用SingleChildScrollView包装一下,
 原来的是这样:

return new Scaffold(       appBar: new AppBar(         title: new Text(&quot;搜索&quot;),       ),       //使用ScrollView包装一下,否则键盘弹出时会报错空间溢出       body: new Column( ... )             ),           ),     ); 修改后: return new Scaffold(       appBar: new AppBar(         title: new Text(&quot;搜索&quot;),       ),       //使用ScrollView包装一下,否则键盘弹出时会报错空间溢出       body: new SingleChildScrollView(             child: new ConstrainedBox(               constraints: new BoxConstraints(                 minHeight: 120.0,               ),               child: new Column(                 mainAxisSize: MainAxisSize.min,                 mainAxisAlignment:  MainAxisAlignment.spaceAround,                 children: &lt;Widget&gt;[                   new Padding(                     padding: EdgeInsets.fromLTRB(0.0,   40.0, 0.0, 10.0),                     child:new Text(&quot;注意&quot;,style: new    TextStyle(fontSize: 18.0,color: Colors.orangeAccent),),                   ),                 ],               ),             ),           ),
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年7月17日 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
对象存储
对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档