【问题标题】:How to set the background image instead of canvasColor for whole drawer?如何为整个抽屉设置背景图像而不是 canvasColor?
【发布时间】:2019-10-18 14:14:45
【问题描述】:
Theme(
      data: Theme.of(context).copyWith(
        canvasColor: ColorPallete().lightBlack,
      ),
      child: Drawer(
        child: ListView(
          children: <Widget>[Column(
            children: <Widget>[
              Container(
                height: 204.0,
                child: DrawerHeader(
                  child:  Stack(
                      children:<Widget>[
                        Center(
                          child: Column(
                            children: <Widget>[
                              DottedBorder(
                                padding: EdgeInsets.all(5.0),
                                borderType: BorderType.Circle,
                                color: ColorPallete().white,
                                child: Container(
                                  height: 74.38,
                                  width: 74.38,
                                  child: CircleAvatar(
                                    backgroundColor: Color(0xFFDADADA),
                                  ),
                                ),
                              ),
                              SizedBox(height: 11.0,),
                              Text('Иван Иванович Иванов',style: TextStyle(
                                  fontSize: 14.0,color: ColorPallete().white
                              ),)
                            ],
                          ),
                        ),
                        Positioned(
                          bottom: 0,
                          right: 0,
                          child: Row(
                            children: <Widget>[
                              Text('Выйти',style: TextStyle(fontSize: 14.0,color: ColorPallete().yellow),),
                              SizedBox(width: 7.0,),
                              Icon(Icons.arrow_forward,color: ColorPallete().yellow,size: 18.0,),
                            ],
                          ),
                        )
                      ]
                  ),
                ),
              ),

【问题讨论】:

    标签: flutter background drawer


    【解决方案1】:

    使用Container 小部件作为您的抽屉,然后您的background image 堆栈和drawer's items 应该是容器的孩子。

        Scaffold(
          ...,
          drawer: Container(
          child: Stack(
            children: <Widget>[
              Image.asset("myBackgroundImage.png"),
              ListView(
                children: <Widget>[
                CircleAvater(),
                ListTile(),
                ListTile(),
                ...
                ],          
             ),    
            ],      
           ),      
          ),
         );
    

    【讨论】:

      猜你喜欢
      • 2022-11-02
      • 2019-09-07
      • 2018-12-18
      • 1970-01-01
      • 1970-01-01
      • 2014-05-01
      • 1970-01-01
      • 2013-06-10
      • 2019-09-21
      相关资源
      最近更新 更多