How to remove extra padding around AppBar leading icon in Flutter

后端 未结 8 1159
陌清茗
陌清茗 2020-12-09 08:33

In my Flutter app, I have this AppBar

Widget setAppBar(){
  return new AppBar(
    title: addAppBarTextWidget(\'Explore\'),
    elevation: 0.0,
    leading:          


        
相关标签:
8条回答
  • 2020-12-09 09:12

    Complete working workaround with some input from Adrian.

    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
        titleSpacing: 0.0,
        title: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            IconButton(
              icon: Icon(Icons.menu),
              onPressed: () => _scaffoldKey.currentState.openDrawer(),
            ),
            Stack(
              alignment: Alignment.center,
              children: <Widget>[
                IconButton(
                  icon: Icon(Icons.mail_outline),
                  onPressed: _onClickNotification,
                ),
                Positioned(
                  top: 12.0,
                  right: 10.0,
                  width: 10.0,
                  height: 10.0,
                  child: Container(
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      color: AppColors.notification,
                    ),
                  ),
                )
              ],
            ),
            Expanded(
              child: Center(child: Text('test')),
            )
          ],
        ),
        automaticallyImplyLeading: false,
        centerTitle: true,
        actions: <Widget>[
          Row(
            children: <Widget>[
              Text('Online'),
              Switch(
                value: true,
                onChanged: (bool value) {},
              )
            ],
          )
        ],
      ),
      drawer: Drawer(
        child: _buildDrawer(),
      ),
      body: Container(
        color: Colors.orange,
      ),
    );
    
    0 讨论(0)
  • 2020-12-09 09:19

    You can't do this because it is a predefined widget. You can, however, do this:

    appBar: AppBar(
      automaticallyImplyLeading: false, // Don't show the leading button
      title: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          IconButton(
            onPressed: () => Navigator.pop(context),
            icon: Icon(Icons.arrow_back, color: Colors.white),
          ),
          // Your widgets here
        ],
      ),
    ),
    

    Where automaticallyImplyLeading: true hides the leading IconButton so you can add your own widgets.

    0 讨论(0)
提交回复
热议问题