改变颤振抽屉背景颜色

问题描述 投票:12回答:5

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

navigation-drawer flutter drawer
5个回答
23
投票

当你在ListViewchild属性中构建你的Drawer时,你可以将Drawer的不同部分包裹在Container中并使用colorContainer属性。

enter image description here

drawer: new Drawer(
        child: new ListView(
          children: <Widget>[
            new Container(child: new DrawerHeader(child: new CircleAvatar()),color: Colors.tealAccent,),
            new Container (
              color: Colors.blueAccent,
              child: new Column(
                children: new List.generate(4, (int index){
                  return new ListTile(
                    leading: new Icon(Icons.info),
                  );
                }),
              ),
            )
          ],
        ),
      ),

如果你已经有了一致的着色设计,那么更好的选择是在你的应用程序根目录的主题属性下定义你的ThemeDataDrawerHeader和正文将跟随你的canvasColor,所以你需要覆盖一个值他们改变颜色:

enter image description here

return new MaterialApp(
....
theme: new ThemeData(
       canvasColor: Colors.redAccent,

       ....),
)

4
投票

Drawer包装Theme的最佳方法,

例如:

  @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
                    ],
                 ),
             ),
        );
  }

2
投票

最简单的方法可能是将ListView包裹在Container中并指定其颜色如下:

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

0
投票

平原背景

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

class MyApp extends StatelessWidget {
  final appTitle = 'Drawer Demo';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: appTitle,
      theme: new ThemeData(
        primarySwatch: Colors.brown, // Your app THEME-COLOR
      ),
      home: MyHomePage(title: appTitle),
    );
  }
}

GRADIENT BACKGROUND将渐变属性添加到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());
  }

enter image description here enter image description here


0
投票

要更改抽屉头颜色,请使用吹码


UserAccountsDrawerHeader( accountName: Text("Ashish Rawat"), accountEmail: Text("[email protected]"), decoration: BoxDecoration( color: const Color(0xFF00897b), ), currentAccountPicture: CircleAvatar( backgroundColor: Theme.of(ctxt).platform == TargetPlatform.iOS ? const Color(0xFF00897b) : Colors.white, child: Text( "A", style: TextStyle(fontSize: 40.0), ), ), ) ,
© www.soinside.com 2019 - 2024. All rights reserved.