How to remove extra padding around AppBar leading icon in Flutter

后端 未结 8 1158
陌清茗
陌清茗 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 08:55

    You can try this, this works fine. when you set the leading = null then extra space of leading widget will remove.

    appBar: new AppBar(
            leading: null,
            titleSpacing: 0.0,
            title: new Text("title"),
          ),
    
    0 讨论(0)
  • 2020-12-09 08:57

    Just add a property called titleSpacing,

    Sample

    appBar: new AppBar(
            leading: new Icon(Icons.android),
            titleSpacing: 0.0,
            title: new Text(widget.title),
          ),
    
    0 讨论(0)
  • 2020-12-09 08:58

    If you just need to move the icon a bit to the left like I did, you can still use the leading property and just set the alignment on the IconButton:

        leading: Builder(
          builder: (BuildContext context) {
            return IconButton(
              onPressed: () => Navigator.pop(context),
              icon: MyIcon(),
              alignment: Alignment(-0.5, 0.0), // move icon a bit to the left
            );
          },
        ),
    
    0 讨论(0)
  • 2020-12-09 09:00

    just set titleSpacing and automaticallyImplyLeading for remove space

    like

    AppBar(
            titleSpacing: 0,
            automaticallyImplyLeading: false,
    )
    
    0 讨论(0)
  • 2020-12-09 09:02

    AppBar(
      leading: Transform.translate(
        offset: Offset(-15, 0),
        child: Icon(Icons.android),
      ),
      titleSpacing: -30,
      centerTitle: false,
      title: Text("Title"),
    )
    

    If you don't want to use any leading widget:

    AppBar(
      title: Text('Title'),
      centerTitle: false,
      titleSpacing: 0,
    )
    
    0 讨论(0)
  • 2020-12-09 09:05

    If you use Widgets from Material package, they are defined respecting Material Design specification document. So if your modification violates this spec, you have to build your own Widget instead of using the Material Widgets.

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