【问题标题】:How to remove trailing hamburger in appbar that is added automatically for endDrawer如何在为 endDrawer 自动添加的 appbar 中删除尾随汉堡包
【发布时间】:2020-02-24 00:53:19
【问题描述】:

我有一个带有endDrawer 的脚手架,我在其中添加了一个自定义图标来打开 endDrawer,但是,出现了结束抽屉的自动汉堡图标,我不知道如何删除它。我找到的所有答案都是为了删除前导答案,这无助于我删除尾随答案。提前致谢。下面是我的代码

Scaffold(
        endDrawer: SafeArea(
                  child: Drawer(
            child: Column(
              children: <Widget>[
                DrawerHeader(child: Text('Trial'),),
                Container(height:54, child: Text('New'),),
                Container(height:54, child: Text('Profile'),),
                Container(height:54, child: Text('Users List'),),
                Container(height:54, child: Text('Add User'),),
                Container(height:54, child: Text('About'),),
              ],
            ),
          ),
        ),
        appBar: AppBar(
          elevation: 0,
          automaticallyImplyLeading: false,
          backgroundColor: Colors.blue,

          title: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Hero(
                tag: 'logo',
                child: Image(
                  image: AssetImage('assets/images/Logo.png'),
                  height: 36,
                  width: 59,
                ),
              ),
              Text(
                'NOTICES',
                style: TextStyle(
                    color: Color(0xAA243782),
                    fontSize: 24,
                    fontFamily: 'Orbitron'),
              ),
              InkWell(
                child: Icon(
                  Icons.list,
                  color: Color(0xAA243782),
                  size: 33,
                ),
                onTap: () {
                  Scaffold.of(context)openEndDrawer();
                },
              ),
            ],
          ),
        ),
        body: Container(
          color: Color(0xAAAB8B3F2),
          child: Center(
            child: Text('Trial'),
          ),
        ));

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    您可以在下面复制粘贴运行完整代码
    第一步:你需要使用actions: [Container()]
    第二步:需要使用GlobalKey打开End Drawer

    代码sn-p 最终的 globalKey = GlobalKey();

     appBar: AppBar(
              actions: [Container()],             
    
     onTap: () {                     
                      globalKey.currentState.openEndDrawer();
                    },      
    

    工作演示

    完整代码

    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,
          ),
          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;
      final globalKey = GlobalKey<ScaffoldState>();
    
      void _incrementCounter() {
        setState(() {
          _counter++;
        });
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          key: globalKey,
            endDrawer: SafeArea(
              child: Drawer(
                child: Column(
                  children: <Widget>[
                    DrawerHeader(
                      child: Text('Trial'),
                    ),
                    Container(
                      height: 54,
                      child: Text('New'),
                    ),
                    Container(
                      height: 54,
                      child: Text('Profile'),
                    ),
                    Container(
                      height: 54,
                      child: Text('Users List'),
                    ),
                    Container(
                      height: 54,
                      child: Text('Add User'),
                    ),
                    Container(
                      height: 54,
                      child: Text('About'),
                    ),
                  ],
                ),
              ),
            ),
            appBar: AppBar(
              actions: [Container()],
              elevation: 0,
              automaticallyImplyLeading: false,
              backgroundColor: Colors.blue,
              title: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Hero(
                    tag: 'logo',
                    child: Image(
                      image: AssetImage('assets/images/Logo.png'),
                      height: 36,
                      width: 59,
                    ),
                  ),
                  Text(
                    'NOTICES',
                    style: TextStyle(
                        color: Color(0xAA243782),
                        fontSize: 24,
                        fontFamily: 'Orbitron'),
                  ),
                  InkWell(
                    child: Icon(
                      Icons.list,
                      color: Color(0xAA243782),
                      size: 33,
                    ),
                    onTap: () {
                      //Scaffold.of(context).openEndDrawer();
                      globalKey.currentState.openEndDrawer();
                    },
                  ),
                ],
              ),
            ),
            body: Container(
              color: Color(0xAAAB8B3F2),
              child: Center(
                child: Text('Trial'),
              ),
            ));
      }
    }
    

    【讨论】:

    • 谢谢。这按预期工作。感谢您的帮助。
    猜你喜欢
    • 2021-11-21
    • 2010-11-05
    • 2010-09-26
    • 2019-06-13
    • 2023-03-10
    • 1970-01-01
    • 2014-12-08
    • 1970-01-01
    相关资源
    最近更新 更多