Navigation drawer 更改颤振抽屉背景色

Navigation drawer 更改颤振抽屉背景色,navigation-drawer,flutter,drawer,Navigation Drawer,Flutter,Drawer,如何更改颤振导航抽屉的背景色? 似乎没有颜色或背景色属性。当您在抽屉的子属性中构建列表视图时,您可以将抽屉的不同部分包装在容器中,并使用容器的颜色属性 最简单的方法可能是将列表视图包装在容器中并指定其颜色,如下所示: drawer: Drawer( child: Container(color: Colors.red, child: new ListView( ... ) ) ) 普通背景 只需使用主题数据中的primarySwatch:Colors.br

如何更改颤振导航抽屉的背景色?
似乎没有颜色或背景色属性。

当您在
抽屉的
子属性中构建
列表视图时,您可以将
抽屉的不同部分包装在
容器中,并使用
容器的
颜色属性


最简单的方法可能是将
列表视图
包装在
容器中
并指定其颜色,如下所示:

drawer: Drawer(
  child: Container(color: Colors.red,
    child: new ListView(
      ...
    )
  )
)

普通背景

只需使用主题数据中的primarySwatch:Colors.brown属性设置所需的主题颜色即可

渐变背景渐变属性添加到AppBar

@override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("profyl.org",
              style: TextStyle(color: Colors.white),
              textDirection: TextDirection.ltr),
          flexibleSpace: Container(
            decoration: new BoxDecoration(
              gradient: new LinearGradient(
                  colors: [
                    const Color(0xFF3366FF),
                    const Color(0xFF00CCFF),
                  ],
                  begin: const FractionalOffset(0.0, 0.0),
                  end: const FractionalOffset(1.0, 0.0),
                  stops: [0.0, 1.0],
                  tileMode: TileMode.clamp),
            ),
          ),
        ),
        body: HomeListPage(),
        drawer: DrawerPage());
  }

主题包装
抽屉的最佳方式

例如:

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        //other scaffold items
        drawer: Theme(
           data: Theme.of(context).copyWith(
                 canvasColor: Colors.blue, //This will change the drawer background to blue.
                 //other styles
              ),
              child: Drawer(
                 child: Column(
                    children: <Widget>[
                       //drawer stuffs
                    ],
                 ),
             ),
        );
  }
@覆盖
小部件构建(构建上下文){
返回脚手架(
//其他脚手架项目
抽屉:主题(
数据:Theme.of(context).copyWith(
canvasColor:Colors.blue,//这会将抽屉背景更改为蓝色。
//其他风格
),
孩子:抽屉(
子:列(
儿童:[
//抽屉里的东西
],
),
),
);
}

要更改抽屉标题颜色,请使用blow code


最简单的方法是:

Drawer(
  child: ListView(
    padding: EdgeInsets.zero,
    children: <Widget>[
      DrawerHeader(
         decoration: BoxDecoration(color:Theme.of(context).bottomAppBarColor),
    )],
  ),
)
抽屉(
子:ListView(
填充:EdgeInsets.zero,
儿童:[
抽屉阅读器(
装饰:盒子装饰(颜色:主题.of(上下文).bottomAppBarColor),
)],
),
)

这将有所帮助

 drawer: Drawer(
    child: Container(
      color: Colors.blueAccent,
      child: ListView(
        padding: EdgeInsets.zero,
        children: <Widget>[
          UserAccountsDrawerHeader(
            decoration: BoxDecoration(
              color: Color(0xFF56ccf2),
            ),
            accountName: Text("User Name Goes"),
            accountEmail: Text("emailaddress@gmail.com"),
            currentAccountPicture: CircleAvatar(
              backgroundColor:
              Theme.of(context).platform == TargetPlatform.iOS
                  ? Color(0xFF56ccf2)
                  : Colors.white,
              child: Text("TK",
                style: TextStyle(fontSize: 50,
                  color: Colors.lightGreenAccent,),),
            ),
          ),
          ListTile(
            title: Text('Home',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 18,
                )),
            contentPadding: EdgeInsets.fromLTRB(20, 5, 0, 5),
            trailing: Icon(Icons.arrow_right,
              color: Colors.white,),
            onTap: () {
              Navigator.of(context).pop();
              Navigator.of(context).push(MaterialPageRoute(
                  builder: (BuildContext context) => HomeScreen()));
            },
          ),
        ],
      ),
    ),
  ),
抽屉:抽屉(
子:容器(
颜色:Colors.blueAccent,
子:ListView(
填充:EdgeInsets.zero,
儿童:[
UserAccountsDrawerHeader(
装饰:盒子装饰(
颜色:颜色(0xFF56ccf2),
),
accountName:Text(“用户名”),
帐户电子邮件:文本(“emailaddress@gmail.com"),
currentAccountPicture:CircleAvatar(
背景颜色:
Theme.of(context.platform==TargetPlatform.iOS
?颜色(0xFF56ccf2)
:颜色。白色,
子:文本(“TK”,
样式:TextStyle(字体大小:50,
颜色:颜色。浅绿色调,),),
),
),
列表砖(
标题:文本('主',
样式:TextStyle(
颜色:颜色,白色,
尺码:18,
)),
contentPadding:EdgeInsets.fromLTRB(20,5,0,5),
尾随:图标(Icons.arrow_right,
颜色:颜色。白色,),
onTap:(){
Navigator.of(context.pop();
导航器.of(上下文).push(MaterialPageRoute(
生成器:(BuildContext上下文)=>HomeScreen());
},
),
],
),
),
),

你可以用一个用扩展小部件包装的容器来包装你抽屉里的任何东西。这样你就可以在那里更改容器的颜色。类似这样的方法可以奏效

Drawer(
    child: Expanded(
      child: Container(
       color: Colors.red,
       child: Text('Tabs'),
      ),
    ),
  )
试试这个

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: Container(
        color: Colors.black,
        child: ListView(
          padding: const EdgeInsets.all(0),
          children: [

          ],
        ),
      ),
    );
  }
}

你可以使用这个代码

drawer: Drawer(
        child: Container(
          //child: Your widget,
          color: Colors.red,
          width: double.infinity,
          height: double.infinity,
        ),
      )

感谢您提供有关主题数据的建议。
.IMHO,使用一致的配色方案是一种方法。由于这是一些非常广泛的代码,您可能应该添加一些解释或相关文档,如文档。@FabianBettag好的。我下次尝试回答问题时会这样做。感谢这对r透明背景谢谢!这在我的项目中效果很好
 drawer: Drawer(
    child: Container(
      color: Colors.blueAccent,
      child: ListView(
        padding: EdgeInsets.zero,
        children: <Widget>[
          UserAccountsDrawerHeader(
            decoration: BoxDecoration(
              color: Color(0xFF56ccf2),
            ),
            accountName: Text("User Name Goes"),
            accountEmail: Text("emailaddress@gmail.com"),
            currentAccountPicture: CircleAvatar(
              backgroundColor:
              Theme.of(context).platform == TargetPlatform.iOS
                  ? Color(0xFF56ccf2)
                  : Colors.white,
              child: Text("TK",
                style: TextStyle(fontSize: 50,
                  color: Colors.lightGreenAccent,),),
            ),
          ),
          ListTile(
            title: Text('Home',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 18,
                )),
            contentPadding: EdgeInsets.fromLTRB(20, 5, 0, 5),
            trailing: Icon(Icons.arrow_right,
              color: Colors.white,),
            onTap: () {
              Navigator.of(context).pop();
              Navigator.of(context).push(MaterialPageRoute(
                  builder: (BuildContext context) => HomeScreen()));
            },
          ),
        ],
      ),
    ),
  ),
Drawer(
    child: Expanded(
      child: Container(
       color: Colors.red,
       child: Text('Tabs'),
      ),
    ),
  )
  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: Container(
        color: Colors.black,
        child: ListView(
          padding: const EdgeInsets.all(0),
          children: [

          ],
        ),
      ),
    );
  }
}
drawer: Drawer(
        child: Container(
          //child: Your widget,
          color: Colors.red,
          width: double.infinity,
          height: double.infinity,
        ),
      )