網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
本文實(shí)例為大家分享了Flutter中抽屜組件Drawer實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
1、概述
Scalfold 是 Flutter MaterialApp 常用的布局 Widget,接受一個(gè) drawer屬性,支持配置 Drawer,可以實(shí)現(xiàn)從側(cè)邊欄拉出導(dǎo)航面板,好處是把一些功能菜單折疊起來(lái),通常Drawer是和Listview組件或者 Column組合使用進(jìn)行縱向布局。Listview組件是豎排排列的,上下可滑動(dòng)。
【注意】如果沒(méi)有設(shè)置 AppBar 的 leading 屬性,則當(dāng)使用 Drawer 的時(shí)候會(huì)自動(dòng)顯示一個(gè) IconButton 來(lái)告訴用戶有側(cè)邊欄(在 Android 上通常是顯示為三個(gè)橫的圖標(biāo))。
2、Drawer組件常見(jiàn)屬性
child:Widget類(lèi)型,可以放置任意可顯示對(duì)象
elevation:double類(lèi)型,組件的Z坐標(biāo)的順序
import 'package:demo_app/pages/drawer/drawer.dart'; import 'package:flutter/material.dart'; class Home extends StatelessWidget { ? @override ? Widget build(BuildContext context) { ? ? return Scaffold( ? ? ? appBar: AppBar(),? ? ? ? body: Container(),? ? ? ? drawer: DrawLayout() ? ? ); ? } }
import 'package:flutter/material.dart'; class DrawLayout extends StatelessWidget { ? @override ? Widget build(BuildContext context) { ? ? return Drawer( ? ? ? child: Text('drawer') ? ? ); ? } }
3、Drawer可以添加頭部效果
- DrawerHeader:展示頭部基本信息
- UserAccountsDrawerHeader:展示用戶頭像、用戶名、email等信息
4、DrawerHeader常用屬性
- child:Widget類(lèi)型,Header里面所顯示的內(nèi)容控件
- padding、margin
- decoration:Decoration類(lèi)型,header區(qū)域的decoration,通常用來(lái)設(shè)置背景顏色或者背景圖片。
import 'package:flutter/material.dart'; class DrawLayout extends StatelessWidget { ? @override ? Widget build(BuildContext context) { ? ? return Drawer( ? ? ? child: ListView( ? ? ? ? padding: EdgeInsets.all(0.0), ? ? ? ? children:[ ? ? ? ? ? DrawerHeader( ? ? ? ? ? ? child: Center( ? ? ? ? ? ? ? child: Text('drawer') ? ? ? ? ? ? ), ? ? ? ? ? ? decoration: BoxDecoration( ? ? ? ? ? ? ? color: Colors.blue ? ? ? ? ? ? ), ? ? ? ? ? ) ? ? ? ? ] ? ? ? ) ? ? ); ? } }
5、UserAccountsDrawerHeader常用屬性
- currentAccountPicture:Widget類(lèi)型,用來(lái)設(shè)置當(dāng)前用戶的頭像
- accountName:Widget類(lèi)型,當(dāng)前用戶的名字
- accountEmail:Widget類(lèi)型,當(dāng)前用戶的 Email
- onDetailsPressed: VoidCallback類(lèi)型,當(dāng) accountName 或者 accountEmail 被點(diǎn)擊的時(shí)候所觸發(fā)的回調(diào)函數(shù),可以用來(lái)顯示其他額外的信息
- otherAccountsPictures:List類(lèi)型,用來(lái)設(shè)置當(dāng)前用戶的其他賬號(hào)的頭像
- decoration:Decoration類(lèi)型,header區(qū)域的decoration,通常用來(lái)設(shè)置背景顏色或者背景圖片。
- margin
import 'package:flutter/material.dart'; class DrawLayout extends StatelessWidget { ? @override ? Widget build(BuildContext context) { ? ? return Drawer( ? ? ? child: ListView( ? ? ? ? padding: EdgeInsets.all(0.0), ? ? ? ? children:[ ? ? ? ? ? UserAccountsDrawerHeader( ? ? ? ? ? ? accountName: Text('username'), ? ? ? ? ? ? accountEmail: Text('username@163.com'), ? ? ? ? ? ? currentAccountPicture: CircleAvatar( ? ? ? ? ? ? ? child: Icon(Icons.home), ? ? ? ? ? ? ), ? ? ? ? ? ? onDetailsPressed: (){}, ? ? ? ? ? ? otherAccountsPictures: [ ? ? ? ? ? ? ? CircleAvatar( ? ? ? ? ? ? ? ? child: Icon(Icons.settings) ? ? ? ? ? ? ? ), ? ? ? ? ? ? ], ? ? ? ? ? ? decoration: BoxDecoration( ? ? ? ? ? ? ? color: Colors.green ? ? ? ? ? ? ), ? ? ? ? ? ), ? ? ? ? ? ListTile( ? ? ? ? ? ? title: Text('設(shè)置'), ? ? ? ? ? ? leading: Icon(Icons.settings), ? ? ? ? ? ? trailing: Icon(Icons.arrow_forward_ios) ? ? ? ? ? ) ? ? ? ? ] ? ? ? ) ? ? ); ? } }
原文鏈接:https://blog.csdn.net/sinat_38328891/article/details/104360312
相關(guān)推薦
- 2024-04-04 mybatis-config.xml的配置
- 2022-04-28 sql?server?累計(jì)求和實(shí)現(xiàn)代碼_MsSql
- 2022-06-29 利用python實(shí)現(xiàn)你說(shuō)我猜游戲的完整實(shí)例_python
- 2022-09-18 GO實(shí)現(xiàn)文件上傳操作_Golang
- 2022-12-11 Rust中Cargo的使用詳解_Rust語(yǔ)言
- 2022-12-24 Golang實(shí)現(xiàn)組合模式和裝飾模式實(shí)例詳解_Golang
- 2022-08-11 如何利用python繪制等高線圖_python
- 2023-01-30 如何使用Flutter實(shí)現(xiàn)手寫(xiě)簽名效果_Android
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門(mén)
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支