第一個知識點: 如何隱藏AppBar?
包一層寬高等於0的父容器就可以了。
return new Scaffold(
appBar: PreferredSize(
child: AppBar(
),
preferredSize: Size(0, 0)),
使用tabbarview時需要AppBar,該怎麼辦?
return DefaultTabController(length: myTabs.length,
child: Scaffold(
appBar:PreferredSize(
child: AppBar(bottom: TabBar(
indicatorColor: Colors.red,
tabs: myTabs,
),toolbarOpacity: 0.0,), //設置透明,隱藏導航欄
preferredSize: Size.fromHeight(50)), //設置標題欄的高度
body: TabBarView(children: myTabs.map((Tab tab){
return Center(child: Text(tab.text),);
}).toList(),),
));
第二個知識點: Column/Row容器裏直接添加ListView會崩潰, 原因是Column測量高度時出了問題。
解決方法:在ListView外邊包一層Expand,這樣測量時就沒問題了。
return new Column(mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
...,
new Expanded(child: ListView.builder(itemCount: 100,
itemBuilder: (context, index) {
return ListTile(leading: new Icon(Icons.message),
title: Text("第$index條"));
},),)
],
);
},
第三個知識點: Flutter裏的彈窗Dialog實際上是打開了一個新路由,是個特殊的Navigator.push, 所以在Flutter裏dialog的彈窗/關閉最終都是指向Navigator.push和Navigator.pop方法。 showDialog在dialog.dart中定義,可以直接調用。
showDialog(context: context,
builder: (_) => AlertDialog(title: Text("提示"),
content: Text("點擊了$index"),
actions: <Widget>[
FlatButton(child: Text('確定'),
onPressed: () {
print("點擊了確定");
Navigator.of(context).pop(); //關閉dialog
_pageChange(index);
},)
],));
第4個知識點: Flutter實現安卓的ViewPager效果,可以用PageView。 Column包含多個控件, 其中一個是PageView。
第5個知識點: Column、PageView、ListView一起用; 實現標題欄不動, 內容區域可以橫向滑動的效果。