如何在抽屉标题的左侧制作另一个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
          ),

results

如何在左侧添加一个帐户图片,例如this, 我试过使用行列,但我认为还有一种更好的方法。 预先感谢。

解决方法

您可以在下面复制粘贴运行完整代码
您可以使用otherAccountsPictures

otherAccountsPictures: [
      CircleAvatar(
        backgroundImage: NetworkImage(
            'https://img.icons8.com/pastel-glyph/2x/user-male.png'),backgroundColor: Colors.white,),],

工作演示

enter image description here

完整代码

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...