如何解决如何在抽屉标题的左侧制作另一个AccountPicture
UserAccountsDrawerHeader(
accountName: Text("xxx"),accountEmail: Text("Flutterdev@gmail.com"),currentAccountPicture: CircleAvatar(
backgroundImage: NetworkImage('https://img.icons8.com/pastel-glyph/2x/user-male.png'),backgroundColor: Colors.white,),decoration: Boxdecoration(
color: Colors.deepOrangeAccent
),
如何在左侧添加另一个帐户图片,例如this, 我试过使用行列,但我认为还有一种更好的方法。 预先感谢。
解决方法
您可以在下面复制粘贴运行完整代码
您可以使用otherAccountsPictures
otherAccountsPictures: [
CircleAvatar(
backgroundImage: NetworkImage(
'https://img.icons8.com/pastel-glyph/2x/user-male.png'),backgroundColor: Colors.white,),],
工作演示
完整代码
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',theme: ThemeData(
primarySwatch: Colors.blue,visualDensity: VisualDensity.adaptivePlatformDensity,home: MyHomePage(title: 'Flutter Demo Home Page'),);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key,this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),drawer: Drawer(
child: Column(
children: <Widget>[
UserAccountsDrawerHeader(
accountName: Text("xxx"),accountEmail: Text("flutterdev@gmail.com"),currentAccountPicture: CircleAvatar(
backgroundImage: NetworkImage(
'https://img.icons8.com/pastel-glyph/2x/user-male.png'),decoration: BoxDecoration(color: Colors.deepOrangeAccent),otherAccountsPictures: [
CircleAvatar(
backgroundImage: NetworkImage(
'https://img.icons8.com/pastel-glyph/2x/user-male.png'),MediaQuery.removePadding(
context: context,child: Expanded(
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,children: <Widget>[
ListTile(
title: Text('Item 1'),onTap: () {
// Update the state of the app.
// ...
},ListTile(
title: Text('Item 2'),body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
Text(
'You have pushed the button this many times:',Text(
'$_counter',style: Theme.of(context).textTheme.headline4,floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,tooltip: 'Increment',child: Icon(Icons.add),);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。