Flutter UI實(shí)現(xiàn)側(cè)拉抽屜菜單
在移動(dòng)開發(fā)中,我們可以通過(guò)底部導(dǎo)航欄、標(biāo)簽頁(yè)或是側(cè)邊抽屜菜單來(lái)實(shí)現(xiàn)導(dǎo)航。這是在小屏幕上可以充分利用空間。我們?cè)O(shè)計(jì)不僅要實(shí)用而且要有趣,這樣才算得上好的 UI 設(shè)計(jì)。這件我們?cè)?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)容是添加一個(gè)列表。DrawerHeader 添加標(biāo)題欄。然后 decoration 中添加背景顏色。然后通過(guò) ListTile 組件來(lái)添加一條一條內(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 事件來(lái)通過(guò) 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);
? ? ? ? ? ? ? },
? ? ? ? ? ? )
? ? ? ? ? ],
? ? ? ? ),
? ? ? ),
? ? );
? }
}以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android選擇圖片或視頻進(jìn)行循環(huán)播放
這篇文章主要為大家詳細(xì)介紹了Android選擇圖片或視頻進(jìn)行循環(huán)播放,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10
Android編程使用加速度傳感器實(shí)現(xiàn)搖一搖功能及優(yōu)化的方法詳解
這篇文章主要介紹了Android編程使用加速度傳感器實(shí)現(xiàn)搖一搖功能及優(yōu)化的方法,結(jié)合實(shí)例形式分析了Android傳感器的調(diào)用方法、參數(shù)含義及具體使用技巧,需要的朋友可以參考下2017-08-08
android獲取當(dāng)前接入點(diǎn)信息判斷是ctwap還是ctnet實(shí)例代碼
這篇文章主要介紹了android獲取當(dāng)前接入點(diǎn)信息判斷是ctwap還是ctnet的方法,大家參考使用吧2013-11-11
Android滑動(dòng)到頂部和底部時(shí)出現(xiàn)的陰影如何去掉
本文給大家介紹android滑動(dòng)到頂部和底部時(shí)出現(xiàn)的陰影去掉的解決方法,本文還涉及到listview各個(gè)屬性的用法介紹,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧2016-10-10
簡(jiǎn)單實(shí)用的Android studio 調(diào)試技巧
這篇文章主要介紹了簡(jiǎn)單實(shí)用的Android studio 調(diào)試技巧的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07
Android自定義View實(shí)現(xiàn)圓弧進(jìn)度效果
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)圓弧進(jìn)度效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-11-11
Android文本輸入框(EditText)輸入密碼時(shí)顯示與隱藏
這篇文章主要介紹了Android文本輸入框(EditText)輸入密碼時(shí)顯示與隱藏的方法和示例,需要的朋友可以參考下2014-12-12

