推广

Flutter–Drawer、DrawerHeader和UserAccountsDrawerHeader组件

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

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://0291.com.cn/post/57379.html

相关文章

ChatGPT 在营销、医疗、教育、公安、新闻写作、文艺评论 ...

ChatGPT 在营销、医疗、教育、公安、新闻写作、文艺评论 ...

ChatGPT 在、医疗、教育、公安、新闻写作、文艺评论 ......

淘宝店铺重新激活等级还在吗(淘宝店铺重开等级还在吗)

淘宝店铺重新激活等级还在吗(淘宝店铺重开等级还在吗)

店铺重新激活之后,店铺原先的等级还在的,如果之前店铺是一个钻,激活后,店铺还是一个钻,如果店铺之前是一颗心,激活之后,店铺还是一颗心,店铺的综合情况也还是原先的。...

【南昌seo】解读外链的原理和友情链接交换注意事项。

【南昌seo】解读外链的原理和友情链接交换注意事项。

外部链接和外部链接的质量在很大程度上决定了网站的权重,并决定了网站在搜索引擎中的排名和流量功能。从搜索引擎的角度来看,如果整个网络上的链接是自然的,那么更多的链接和更好的质量的网站应该更重要;高质量、高权重的网站应该指出,网站应该是重要的,相当于一定数量的有名投票批准;链接使用的锚文本也是链接网页主...

关于SEO有太多知识点要了解。

关于SEO有太多知识点要了解。

之前 写了一篇百度霸屏实操同享 ,关于SEO因为太多知识点,调集性文章写不完,所以单独出一篇文章。关于SEO太多的人具有不同的了解,这篇文章也是出于我个人对SEO的了解,希望对我们有帮忙。我随时等候需求SEO排名优化的你呈现哦。 SEO开展至今,我以为现已跨过了许多个时代了,之前的就...

网站SEO推广迅速提升关键词排名的技巧。

网站SEO推广迅速提升关键词排名的技巧。

做过竞价排名的都知道,花钱买流量不仅贵,换来的也只是短期效益,有时甚至没有效益。用大把的银子去维持高排名,绝不是长久之计。不如试试SEO搜索引擎优化,今天小编给大家介绍几种能提升排名的搜索引擎优化小技巧。 1、网址关键词应简短 URL结构是网站开发的重要因素,理想情况下,网站的所有页面都将被...

淘宝开店认证怎么认证(淘宝店铺怎么认证)

淘宝开店认证怎么认证(淘宝店铺怎么认证)

进入淘宝的淘宝卖家中心,随后寻找【完全免费开店】,点开完全免费开店后会进到下一个网页页面,随后你寻找【淘宝开店认证】→【马上认证】。...

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

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