Raf*_*san 9 dart flutter flutter-layout
在我的Flutter应用程序中,我有这个AppBar
Widget setAppBar(){
return new AppBar(
title: addAppBarTextWidget('Explore'),
elevation: 0.0,
leading: addLeadingIcon(),
actions: <Widget>[
addAppBarActionWidget(Constant.iconNotification, 22.0, 16.0, 8.0),
addAppBarActionWidget(Constant.iconProfile, 30.0, 30.0, 15.0)
],
);
}
Widget addLeadingIcon(){
return new Container(
height: 25.0,
width: 25.0,
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
margin: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
child: new Stack(
alignment: AlignmentDirectional.center,
children: <Widget>[
new Image.asset(
Constant.iconNotification,
width: 25.0,
height: 25.0,
),
new FlatButton(
onPressed: (){
onLeadingShowCategoryClick();
}
)
],
),
);
}
Run Code Online (Sandbox Code Playgroud)
看起来像:
正如你在AppBar上看到的那样,领先图标周围有一些额外的填充.如何删除这个额外的填充.
Vin*_*mar 21
只需添加一个名为titleSpacing的属性,
样品
appBar: new AppBar(
leading: new Icon(Icons.android),
titleSpacing: 0.0,
title: new Text(widget.title),
),
Run Code Online (Sandbox Code Playgroud)
Cop*_*oad 21
简短的回答:
AppBar(
leadingWidth: 8, // <-- Use this
centerTitle: false, // <-- and this
leading: Icon(Icons.android),
title: Text('Title'),
)
Run Code Online (Sandbox Code Playgroud)
更多定制:
AppBar(
leading: Transform.translate(
offset: Offset(-15, 0),
child: Icon(Icons.android),
),
titleSpacing: -30,
centerTitle: false,
title: Text("Title"),
)
Run Code Online (Sandbox Code Playgroud)
如果您不想使用任何领先的小部件:
AppBar(
title: Text('Title'),
centerTitle: false,
titleSpacing: 0,
)
Run Code Online (Sandbox Code Playgroud)
Bha*_*pal 16
添加标题间距可以解决这个问题。
AppBar(
centerTitle: false,
automaticallyImplyLeading: false,
titleSpacing: 0
)
Run Code Online (Sandbox Code Playgroud)
小智 12
您无法执行此操作,因为它是预定义的小部件。但是,您可以这样做:
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
],
),
),
Run Code Online (Sandbox Code Playgroud)
哪里automaticallyImplyLeading: true隐藏了领导,IconButton以便您可以添加自己的小部件。
只需设置titleSpacing和automaticallyImplyLeading删除空间
喜欢
AppBar(
titleSpacing: 0,
automaticallyImplyLeading: false,
)
Run Code Online (Sandbox Code Playgroud)
小智 8
使用 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,
),
);
Run Code Online (Sandbox Code Playgroud)
小智 7
你可以试试这个,这很好用。当您设置前导 = null 时,前导小部件的额外空间将被删除。
appBar: new AppBar(
leading: null,
titleSpacing: 0.0,
title: new Text("title"),
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11682 次 |
| 最近记录: |