推广

Flutter–Drawer、DrawerHeader和UserAccountsDrawerHeader组件

iseeyu2年前 (2024-02-21)推广131

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()),
    );

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(),
              ],
            )),

          ),
    );

3333.png

扫描二维码推送至手机访问。

版权声明:本文由西安泽虎代运营发布,如需转载请注明出处。

转载请注明出处https://www.0291.com.cn/post/57379.html

相关文章

美媒:TOP500富豪上半年财富飙涨8520亿美元

美媒:TOP500富豪上半年财富飙涨8520亿美元

【环球时报特约记者 甄翔】据美国彭博社3日报道,彭博亿万富翁指数显示,全球排名前500位的富豪2023年上半年总身家增加了8520亿美元。显示,在刚过去的6个月中,该榜单上前500名顶级富豪的财富平均每天增加1400万美元,创下2020年下半年以来的最佳表现。而这一增长恰好...

加盟天猫小店怎么样,代入驻天猫要花多少费用(天猫小店一年能赚多少)

加盟天猫小店怎么样,代入驻天猫要花多少费用(天猫小店一年能赚多少)

天猫品牌授权,在保留小店名称的基础上,从店招、店内装修到助销物料加入天猫元素,基本上,就是帮你增加陌生客源的信任感,同时可以给“天猫小店”品牌刷存在感。...

B站百大up主内容趋势分析

B站百大up主内容趋势分析

  1月13日,bilibili 2022年度百大UP主已经揭开帷幕,今年延续2021年的评审标准,依然从专业性、影响力、创新性三个维度进行评选。 来源-B站 这套评审标准已经实施两年,早期的百大评选上榜的更多是来自知名度高、影响力广的UP主,反观这两年的百大榜单,首...

关键词排名首页为好的seo优化效果合适吗。

关键词排名首页为好的seo优化效果合适吗。

测试网站排名优化标准的因素不仅是关键词的排名,更是很多不懂SEO的朋友容易进入的一种误解。他们会认为衡量网站排名优化效果的标准是看是否在前列,尤其是对于网站目标核心关键词的排名,认为进入首页的关键词排名是合格的。因此,在优化网站排名时,很多合约都以关键词排名首页为报价标准。测试网站排名优化标准的因素...

企业网站关键词排名如何上首页。

企业网站关键词排名如何上首页。

伴随互联网行业的发展,现在很多的企业开始做网络优化,而今做网络SEO排名的企业数量也变得越来越多,行业市场上的竞争度也在随之不断地增长,那么企业网站关键词排名如何上首页? 搜索引擎如何判断页面的质量。网页的标题必须和网页的内容息息相关,如果我们更新的文章内容相关比较低,主题也不少很突出,...

为什么发展越好的企业越重视新闻推广

为什么发展越好的企业越重视新闻推广

对于身处在互联网时代的企业提起新闻大家已经都不陌生,它是互联网时代企业想要在网络上获得一席之地不可或缺的一部分,如果你的企业也在做新闻推广,你就会发现往往发展越好的企业越重视新闻推广,那这是为什么呢?一、维护企业正面形象企业做的大了,往往会伴随着一些对自己不利的负面信息,这...

现在,非常期待与您的又一次邂逅

我们努力让每一部企业宣传片和抖音短视频成为商业大片