Aqi*_*rid 5 flutter flutter-layout flutter-appbar flutter-navigation flutter-image
我想知道我是否可以在 flutter app drawer header 中使用背景图像而不是颜色,有什么办法吗?
我可以自定义颜色,但我想知道是否有任何属性可以使用自定义图像更改颜色。
Sho*_*din 14
您可以在 DrawerHeader 中使用装饰将图像设置为抽屉标题
return Scaffold(
appBar: AppBar(title: Text(title)),
body: Center(child: Text('some text')),
drawer: Drawer(
// Add a ListView to the drawer. This ensures the user can scroll
// through the options in the drawer if there isn't enough vertical
// space to fit everything.
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header'),
decoration: BoxDecoration(
color: Colors.blue,
image: DecorationImage(
image: AssetImage("assets/gold.jpg"),
fit: BoxFit.cover)
),
),
ListTile(
title: Text('Item 1'),
onTap: () {
// Update the state of the app
// ...
// Then close the drawer
Navigator.pop(context);
},
),
ListTile(
title: Text('Item 2'),
onTap: () {
// Update the state of the app
// ...
// Then close the drawer
Navigator.pop(context);
},
),
],
),
),
);
Run Code Online (Sandbox Code Playgroud)
另请参阅此链接