【问题标题】:how to make another AccountPicture in the left side of the drawer header如何在抽屉标题的左侧制作另一个 AccountPicture
【发布时间】:2020-09-23 05:03:05
【问题描述】:
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, 我试过使用行列,但我认为有更好的方法来做到这一点。 提前致谢。

【问题讨论】:

    标签: flutter layout drawer


    【解决方案1】:

    您可以在下面复制粘贴运行完整代码
    你可以使用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'),
                    backgroundColor: Colors.white,
                  ),
                  decoration: BoxDecoration(color: Colors.deepOrangeAccent),
                  otherAccountsPictures: [
                    CircleAvatar(
                      backgroundImage: NetworkImage(
                          'https://img.icons8.com/pastel-glyph/2x/user-male.png'),
                      backgroundColor: Colors.white,
                    ),
                  ],
                ),
                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'),
                          onTap: () {
                            // Update the state of the app.
                            // ...
                          },
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
          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),
          ),
        );
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      相关资源
      最近更新 更多