如何为整个抽屉设置背景图像而不是canvasColor?

时间:2019-10-18 14:14:45

标签: flutter background drawer

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

1 个答案:

答案 0 :(得分:0)

使用Container小部件作为抽屉,然后将background imagedrawer's items的堆栈作为容器的子容器。

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