【问题标题】:change drawer item icon to right flutter将抽屉项目图标更改为右颤动
【发布时间】:2020-06-24 08:42:48
【问题描述】:

我在flutter中使用了抽屉,我用结束抽屉来改变抽屉的方向,

但我还需要将抽屉项目图标的方向更改为向右颤动,我该怎么做?

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    您可以使用ListTile 小部件实现此目的

    试试这个方法

    import 'package:flutter/foundation.dart';
    import 'package:flutter/material.dart';
    
    void main() => runApp( HomeApp());
    
    class HomeApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        // TODO: implement build
        return new MaterialApp(
          theme: new ThemeData(
              primarySwatch: Colors.deepPurple,
              brightness: Brightness.light,
              accentColor: Colors.red),
          home: new HomePage(),
        );
      }
    }
    
    class HomePage extends StatefulWidget {
      @override
      _HomePageScreen createState() => _HomePageScreen();
    }
    
    class _HomePageScreen extends State<HomePage> {
      @override
      Widget build(BuildContext context) {
        return  Scaffold(
          appBar:  AppBar(
            title:  Text("Home"),
          ),
          endDrawer: Drawer(
            child:  ListView(
              padding:  EdgeInsets.all(0.0),
              children: <Widget>[
                 UserAccountsDrawerHeader(
                  accountName:  Text("Nilesh Rathod"),
                  accountEmail:  Text("nilesh@gmail.com"),
                  currentAccountPicture:  CircleAvatar(
                    backgroundColor: Colors.white,
                    child:  Text("Nilu"),
                  ),
                  otherAccountsPictures: <Widget>[
                     CircleAvatar(
                      backgroundColor: Colors.white,
                      child:  Text("Pilu"),
                    ),
                  ],
                ),
                 ListTile(
                  title:  Text("Home"),
                  trailing:  Icon(Icons.new_releases),
                ),
                 Divider(),
                 ListTile(
                  title:  Text("Profile"),
                  trailing:  Icon(Icons.person),
                  onTap: () => {},
                ),
                 Divider(),
                 ListTile(
                  title:  Text("Tab Layout"),
                  trailing:  Icon(Icons.person),
                  onTap: () => {},
                ),
                 Divider(),
                 ListTile(
                  title:  Text("Comman View Demo"),
                  trailing:  Icon(Icons.person),
                  onTap: () => {},
                ),
                 Divider(),
                 ListTile(
                  title:  Text("Close"),
                  trailing:  Icon(Icons.close),
                  onTap: () => Navigator.of(context).pop(),
                ),
              ],
            ),
          ),
          body:  Center(
            child: Text("Home Screen"),
          ),
        );
      }
    }
    

    示例代码

    【讨论】:

    • 谢谢,但我也可以将文本向右移动吗?因为我使用了正确的语言
    【解决方案2】:

    利用 ListTile trailing 属性

             ListTile(
              title:  Text("text"),
              trailing:  Icon(Icons.account),
              onTap:null,
            ),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-20
      • 1970-01-01
      • 2017-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多