Flutter UI實(shí)現(xiàn)側(cè)拉抽屜菜單
在移動開發(fā)中,我們可以通過底部導(dǎo)航欄、標(biāo)簽頁或是側(cè)邊抽屜菜單來實(shí)現(xiàn)導(dǎo)航。這是在小屏幕上可以充分利用空間。我們設(shè)計不僅要實(shí)用而且要有趣,這樣才算得上好的 UI 設(shè)計。這件我們在 Scaffold 通常是上下結(jié)構(gòu),頭部是標(biāo)題欄下面主界面。
@override
Widget build(BuildContext context) {
? // TODO: implement build
? return Scaffold(
? ? appBar: AppBar(title: Text(title),),
? ? body: Center(child: Text('$title Demo'),),
? ),
?),
);Scaffold 除了 appBar 和 body 屬性以為還有 drawer 屬性方便我們定義側(cè)邊抽屜。
@override
Widget build(BuildContext context) {
? // TODO: implement build
? return Scaffold(
? ? appBar: AppBar(title: Text(title),),
? ? body: Center(child: Text('$title Demo'),),
? ? drawer: Drawer(
? ? )
? ? ),
? ),
);這樣便可以在 child 為側(cè)拉抽屜添加內(nèi)容,內(nèi)容是添加一個列表。DrawerHeader 添加標(biāo)題欄。然后 decoration 中添加背景顏色。然后通過 ListTile 組件來添加一條一條內(nèi)容
child: ListView(
? ? ? padding: EdgeInsets.zero,
? ? ? children: <Widget>[
? ? ? ? DrawerHeader(
? ? ? ? ? child: Text('$title Demo'),
? ? ? ? ? decoration: BoxDecoration(
? ? ? ? ? ? color: Colors.blue
? ? ? ? ? ),
? ? ? ? ),
? ? ? ? ListTile(
? ? ? ? ? title: Text("React"),
? ? ? ? ? onTap: (){
? ? ? ? ? ? Navigator.pop(context);
? ? ? ? ? },
? ? ? ? ),
? ? ? ? ListTile(
? ? ? ? ? ?title: Text("Vue"),
? ? ? ? ? ?onTap: (){
? ? ? ? ? ? Navigator.pop(context);
? ? ? ? ? ?},
? ? ? ? )
? ? ? ],
),為 ListTile 添加 onTap 事件來通過 Navigator 返回到主界面。
ListTile(
? ? ? title: Text("Vue"),
? ? ? onTap: (){
? ? ? ? Navigator.pop(context);
? ? ? },
?)完整代碼
import 'package:flutter/material.dart';
?
class DrawerApp extends StatelessWidget{
?
? final appTitle = "側(cè)滑抽屜";
?
? @override
? Widget build(BuildContext context) {
? ? // TODO: implement build
? ? return MaterialApp(
? ? ? title: appTitle,
? ? ? home: MyHomePage(title:appTitle),
? ? );
? }
??
}
?
class MyHomePage extends StatelessWidget{
? final String title;
? MyHomePage({Key key,this.title}):super(key:key);
?
? @override
? Widget build(BuildContext context) {
? ? // TODO: implement build
? ? return Scaffold(
? ? ? appBar: AppBar(title: Text(title),),
? ? ? body: Center(child: Text('$title Demo'),),
? ? ? drawer: Drawer(
? ? ? ? child: ListView(
? ? ? ? ? padding: EdgeInsets.zero,
? ? ? ? ? children: <Widget>[
? ? ? ? ? ? DrawerHeader(
? ? ? ? ? ? ? child: Text('$title Demo'),
? ? ? ? ? ? ? decoration: BoxDecoration(
? ? ? ? ? ? ? ? color: Colors.blue
? ? ? ? ? ? ? ),
? ? ? ? ? ? ),
? ? ? ? ? ? ListTile(
? ? ? ? ? ? ? title: Text("React"),
? ? ? ? ? ? ? onTap: (){
? ? ? ? ? ? ? ? Navigator.pop(context);
? ? ? ? ? ? ? },
? ? ? ? ? ? ),
? ? ? ? ? ? ListTile(
? ? ? ? ? ? ? title: Text("Vue"),
? ? ? ? ? ? ? onTap: (){
? ? ? ? ? ? ? ? Navigator.pop(context);
? ? ? ? ? ? ? },
? ? ? ? ? ? )
? ? ? ? ? ],
? ? ? ? ),
? ? ? ),
? ? );
? }
}以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android自定義ViewPagerIndicator實(shí)現(xiàn)炫酷導(dǎo)航欄指示器(ViewPager+Fragment)
這篇文章主要為大家詳細(xì)介紹了Android自定義ViewPagerIndicator實(shí)現(xiàn)炫酷導(dǎo)航欄指示器,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02
Android 友盟第三方登錄與分享的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android 友盟第三方登錄與分享的實(shí)現(xiàn)代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
Android實(shí)現(xiàn)Activity、Service與Broadcaster三大組件之間互相調(diào)用的方法詳解
這篇文章主要介紹了Android實(shí)現(xiàn)Activity、Service與Broadcaster三大組件之間互相調(diào)用的方法,結(jié)合實(shí)例形式詳細(xì)分析了Activity、Service與Broadcaster三大組件相互調(diào)用的原理,實(shí)現(xiàn)方法與相關(guān)注意事項,需要的朋友可以參考下2016-03-03
Android使用CircleImageView實(shí)現(xiàn)圓形頭像的方法
圓形頭像看起來非常美觀,下文通過實(shí)例代碼給大家介紹android中使用CircleImageView實(shí)現(xiàn)圓形頭像的方法,一起看看吧2016-09-09
Android 使用 Scroller 實(shí)現(xiàn)平滑滾動功能的示例代碼
這篇文章主要介紹了Android 使用 Scroller 實(shí)現(xiàn)平滑滾動功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-07
Android之線程池ThreadPoolExecutor的簡介
今天小編就為大家分享一篇關(guān)于Android之線程池ThreadPoolExecutor的簡介,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03
Android中使用SeekBar拖動條實(shí)現(xiàn)改變圖片透明度(代碼實(shí)現(xiàn))
這篇文章主要介紹了Android中使用SeekBar拖動條實(shí)現(xiàn)改變圖片透明度,需要的朋友可以參考下2020-01-01

