網(wǎng)站首頁 編程語言 正文
在移動開發(fā)中,我們可以通過底部導航欄、標簽頁或是側(cè)邊抽屜菜單來實現(xiàn)導航。這是在小屏幕上可以充分利用空間。我們設計不僅要實用而且要有趣,這樣才算得上好的 UI 設計。這件我們在 Scaffold 通常是上下結(jié)構(gòu),頭部是標題欄下面主界面。
@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 添加標題欄。然后 decoration 中添加背景顏色。然后通過 ListTile 組件來添加一條一條內(nèi)容
child: ListView( ? ? ? padding: EdgeInsets.zero, ? ? ? children:[ ? ? ? ? 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:[ ? ? ? ? ? ? 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); ? ? ? ? ? ? ? }, ? ? ? ? ? ? ) ? ? ? ? ? ], ? ? ? ? ), ? ? ? ), ? ? ); ? } }
原文鏈接:https://blog.csdn.net/shanghaibao123/article/details/107629748
相關(guān)推薦
- 2022-12-24 Go中函數(shù)的使用細節(jié)與注意事項詳解_Golang
- 2022-04-30 C語言實現(xiàn)考勤管理系統(tǒng)_C 語言
- 2021-12-15 C#?多線程學習之基礎入門_C#教程
- 2022-08-30 Python正則表達式re.compile()和re.findall()詳解_python
- 2022-03-16 Oracle表空間管理和用戶管理介紹(oracle表空間與用戶的關(guān)系)
- 2022-04-09 C語言實現(xiàn)計算器的兩種方法_C 語言
- 2022-10-14 MapStruct 代碼生成器
- 2023-07-26 TypeScript的類型推導
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支