Flutter–Drawer、DrawerHeader和UserAccountsDrawerHeader组件

1111.png

五、DrawerHeader的源码

const DrawerHeader({
    Key key,
    this.decoration,//header区域的背景
    this.margin = const EdgeInsets.only(bottom: 8.0),//外边距
    this.padding = const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 8.0),//内边距
    this.duration = const Duration(milliseconds: 250),//decoration背景发生变化时动画时间
    this.curve = Curves.fastOutSlowIn,//decoration背景发生curve曲线变化
    @required this.child,
  }) : super(key: key);

六、DrawerHeader属性介绍

属性 说明
child 子组件
decoration header区域的背景
margin 外边距
padding 内边距
duration decoration背景发生变化时动画持续时间
curve decoration背景发生变化会使用curve 设置的曲线变化

七、Drawer和DrawerHeader配合使用的demo

CircleAvatar设置头像组件
Divider分割线组件

return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text("Drawer学习"),
          ),
          drawer: Drawer(
              child: ListView(
                //隐藏黑色导航条
                padding: EdgeInsets.zero,
            children: [
                DrawerHeader(
                  child: Text(
                    "ysl",
                   style: TextStyle(
                     color: Colors.white
                   ),

                  ),
                  decoration: BoxDecoration(
                      image: DecorationImage(
                          image: NetworkImage(
                              "https://www.itying.com/images/flutter/1.png"),
                          fit: BoxFit.cover)),
                ),
                ListTile(
                  leading: CircleAvatar(
                    child: Icon(Icons.home),
                  ),
                  title: Text("我的主页"),
                ),
                Divider(),
                ListTile(
                  leading: CircleAvatar(
                    child: Icon(Icons.people),
                  ),
                  title: Text("个人中心"),
                  onTap: (){
                    //点击销毁抽屉布局
                    Navigator.pop(context);
                  },
                ),
                Divider(),
            ],
          )),
          body: Container()),
    );

Flutter–Drawer、DrawerHeader和UserAccountsDrawerHeader组件

22222.png

八、UserAccountsDrawerHeader的源码

const UserAccountsDrawerHeader({
    Key key,
    this.decoration,//Header的背景样式
    this.margin = const EdgeInsets.only(bottom: 8.0),//外边距
    this.currentAccountPicture,//用户头像
    this.otherAccountsPictures,//别的头像集合
    @required this.accountName,//用户名
    @required this.accountEmail,//用户email
    this.onDetailsPressed,//accountName 或者 accountEmail 被点击的时候所触发的回调函数
    this.arrowColor = Colors.white,
  }) : super(key: key);

九、UserAccountsDrawerHeader属性介绍

属性 说明
decoration Header的背景样式
margin 外边距
currentAccountPicture 用户头像
otherAccountsPictures 别的用户头像集合
accountName 用户名
accountEmail 用户的email
onDetailsPressed accountName 或者 accountEmail 被点击的时候所触发的回调函数

十Drawer和UserAccountsDrawerHeader配合使用的demo

return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text("Drawer学习"),
          ),
        drawer: Drawer(
            child: ListView(
              //隐藏黑色导航条
              padding: EdgeInsets.zero,
              children: [
                UserAccountsDrawerHeader(
                  decoration: BoxDecoration(
                    image: DecorationImage(
                      image: NetworkImage("https://www.itying.com/images/flutter/1.png"),fit: BoxFit.cover
                    )
                  ),
                  currentAccountPicture: CircleAvatar(
                    backgroundImage:NetworkImage("https://www.itying.com/images/flutter/2.png"),
                  ),
                  //别的用户头像,直接用方块代替
                  otherAccountsPictures: [
                    Container(
                      color: Colors.red,
                    ),
                    Container(
                      color: Colors.yellow,
                    )
                  ],
                  accountName: Text("ysl"),
                  accountEmail: Text("111111@email"),
                  arrowColor: Colors.yellow,
                  onDetailsPressed: (){
                    print("点击了内容");
                  },


                ),
                ListTile(
                  leading: CircleAvatar(
                    child: Icon(Icons.home),
                  ),
                  title: Text("我的主页"),
                ),
                Divider(),
                ListTile(
                  leading: CircleAvatar(
                    child: Icon(Icons.people),
                  ),
                  title: Text("个人中心"),
                  onTap: (){
                    //点击销毁抽屉布局
                    Navigator.pop(context);
                  },
                ),
                Divider(),
              ],
            )),

          ),
    );

Flutter–Drawer、DrawerHeader和UserAccountsDrawerHeader组件

3333.png

文章均来自互联网如有不妥请联系作者删除QQ:314111741 地址:http://www.mqs.net/post/14925.html

相关阅读

  • 淘宝怎么运营推广(中小卖家必学的操作思路)

    淘宝怎么运营推广(中小卖家必学的操作思路)

    淘宝在很长一段时间内,一直被认为是中国最大的电子商务平台。人们在这里购物,与在别处购物一样,会感觉到很便捷、很实惠。因此,随着电商行业的发展。如今,淘宝网站的活跃用户数已经超过了1亿人(目前该数据仅统计了部分用户)。而作为一个淘宝...

    2025.12.09 14:15:37作者:iseeyuTags:运营
  • 如何保证缓存和数据的双写一致性

    如何保证缓存和数据的双写一致性

    image 但是在更新缓存方面,对于更新完数据库,是更新缓存呢,还是删除缓存。又或者是先删除缓存,再更新数据库,其实大家存在很大的争议。目前没有一篇全面的博客,对这几种方案进行解析。于是博主战战兢兢,顶着被大家喷的风险,写了这篇...

    2025.12.09 09:28:14作者:iseeyu
  • 【百度搜索引擎优化】如何快速了解百度搜索引擎优化的知识?(搜索引擎优化基本)

    【百度搜索引擎优化】如何快速了解百度搜索引擎优化的知识?(搜索引擎优化基本)

    在百度输入SEO优化,下拉框就有很多关键词,SEO优化工具,SEO查询,SEO技巧,SEO优化方案,SEO报价,SEO优化教程,SEO优化软件,SEO优化怎么做,等等,相关搜索也有很多长尾关键词。还可以加入一些群,找些大牛问下,向这些大牛学...

    2025.12.09 07:37:38作者:iseeyu

添加新评论