Flutter Error: Navigator operation requested with a context that does not include a Navigator
解决办法:不能直接在new MaterialApp
中调用Navigator.of(context).push()
- RefreshIndicator在ListView条目较少时不触发下拉刷新 RefreshIndicator是根据下拉时的偏移量触发刷新,当条目较少时(未占满一个屏幕),ListView不能滚动,所以无法触发下拉刷新,给ListView的physice属性设置值为new AlwaysScrollableScrollPhysics(),让ListView在任何情况下都可以滑动,也就可以触发RefreshIndicator的刷新。
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; }
Flutter
图片资源加载失败unable to load image/assets
需要在项目中的pubspec.yaml
中进行配置assets
,将images
文件下的图片都加到此位置
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
所订阅的对象中,例如Stream
或ChangeNotifier
对象,其引用存储在StatefulWidget
的最终字段中。info: Name non-constant identifiers using lowerCamelCase.
使用小写字母进行命名变量,否则会报这个warning
,例如:feedUrl
或者是title
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
【flutter 溢出BUG】 bottom overflowed by 104 PIXELS
一开始直接使用Scaffold布局,body:new Column 然后结果调出键盘的时候就报这个错了
解决办法是使用SingleChildScrollView包装一下,
原来的是这样:
return new Scaffold( appBar: new AppBar( title: new Text("搜索"), ), //使用ScrollView包装一下,否则键盘弹出时会报错空间溢出 body: new Column( ... ) ), ), ); 修改后: return new Scaffold( appBar: new AppBar( title: new Text("搜索"), ), //使用ScrollView包装一下,否则键盘弹出时会报错空间溢出 body: new SingleChildScrollView( child: new ConstrainedBox( constraints: new BoxConstraints( minHeight: 120.0, ), child: new Column( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[ new Padding( padding: EdgeInsets.fromLTRB(0.0, 40.0, 0.0, 10.0), child:new Text("注意",style: new TextStyle(fontSize: 18.0,color: Colors.orangeAccent),), ), ], ), ), ),