笔录Flutter(十) 侧边栏(Drawer)、UserAccountsDrawerHeader

Flutter练习Demo

Drawer、UserAccountsDrawerHeader常用属性

  1. Drawer
 const Drawer({
    Key key,
    this.elevation = 16.0,
    this.child,
    this.semanticLabel,
  }) : assert(elevation != null && elevation >= 0.0),
       super(key: key);

  1. UserAccountsDrawerHeader
const UserAccountsDrawerHeader({
    Key key,
    this.decoration,
    this.margin = const EdgeInsets.only(bottom: 8.0),
    this.currentAccountPicture,// 当前账户头像
    this.otherAccountsPictures,//  其他账户头像
    @required this.accountName,// 账户名字
    @required this.accountEmail,// 账户邮箱
    this.onDetailsPressed,
  }) : super(key: key)

使用

效果图:
在这里插入图片描述
功能:

  1. 只在Home页面有侧边栏
  2. 自定义leading图片展示,实现点击展开侧边栏
  3. UserAccountsDrawerHeader的使用
  4. 点击侧边栏item跳转页面
功能一 Home页面有侧边栏

配置侧边栏:

 drawer: LeftDrawerPage()),
 // 编写一个侧边栏页面
功能二 leading点击打开侧边栏

在这里插入图片描述

功能三 UserAccountsDrawerHeader的使用
 UserAccountsDrawerHeader(
              //其他账户头像  会显示右上角
//            otherAccountsPictures: <Widget>[
//              ClipOval(
//                child: Image.asset(
//                  "images/x.jpg",
//                  width: 50,
//                  height: 50,
//                  fit: BoxFit.cover,
//                ),
//              ),
//              ClipOval(
//                child: Image.asset(
//                  "images/s.jpg",
//                  width: 50,
//                  height: 50,
//                  fit: BoxFit.cover,
//                ),
//              ),
//            ],

            currentAccountPicture: Center(//当前账户头像
              //要想控制头像的大小需要用Center包裹
              child: ClipOval(
                child: Image.asset(
                  "images/z.jpg",
                  width: 70,
                  height: 70,
                  fit: BoxFit.cover,
                ),
              ),
            ),
            accountName: Text("Six某人"),
            accountEmail: Text("1828088521@qq.com"),
            decoration: BoxDecoration(
              image: DecorationImage(
              //设置UserAccountsDrawerHeader背景图
                  image: AssetImage("images/hy.jpg"), fit: BoxFit.cover),
            ),
          ),
功能四 点击侧边栏item跳转页面
//点击跳转前先关闭侧边栏
   onTap: () {
        // 跳转之前先把侧边栏关闭掉
        Navigator.of(context).pop();
        Navigator.pushNamed(context, "/routeDrawerItemPage");
      },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值