时间:2022-06-22 09:38:27 | 栏目:Android代码 | 点击:次
本文实例为大家分享了Flutter中抽屉组件Drawer实现代码,供大家参考,具体内容如下
Scalfold 是 Flutter MaterialApp 常用的布局 Widget,接受一个 drawer属性,支持配置 Drawer,可以实现从侧边栏拉出导航面板,好处是把一些功能菜单折叠起来,通常Drawer是和Listview组件或者 Column组合使用进行纵向布局。Listview组件是竖排排列的,上下可滑动。
【注意】如果没有设置 AppBar 的 leading 属性,则当使用 Drawer 的时候会自动显示一个 IconButton 来告诉用户有侧边栏(在 Android 上通常是显示为三个横的图标)。
child:Widget类型,可以放置任意可显示对象
elevation:double类型,组件的Z坐标的顺序
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') ); } }
import 'package:flutter/material.dart'; class DrawLayout extends StatelessWidget { @override Widget build(BuildContext context) { return Drawer( child: ListView( padding: EdgeInsets.all(0.0), children: <Widget>[ DrawerHeader( child: Center( child: Text('drawer') ), decoration: BoxDecoration( color: Colors.blue ), ) ] ) ); } }
import 'package:flutter/material.dart'; class DrawLayout extends StatelessWidget { @override Widget build(BuildContext context) { return Drawer( child: ListView( padding: EdgeInsets.all(0.0), children: <Widget>[ UserAccountsDrawerHeader( accountName: Text('username'), accountEmail: Text('username@163.com'), currentAccountPicture: CircleAvatar( child: Icon(Icons.home), ), onDetailsPressed: (){}, otherAccountsPictures: <Widget>[ CircleAvatar( child: Icon(Icons.settings) ), ], decoration: BoxDecoration( color: Colors.green ), ), ListTile( title: Text('设置'), leading: Icon(Icons.settings), trailing: Icon(Icons.arrow_forward_ios) ) ] ) ); } }