![](/img/trans.png)
[英]How to remove extra padding around AppBar leading icon in Flutter
[英]how you can remove the padding between the icon for the drawer in the appBar and the Search Icon in flutter
我制作了appBar並向其添加了一個抽屜並搜索圖標抽屜圖標和搜索圖標之間存在填充問題我無法擺脫它
這是代碼:
class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
titleSpacing: 0,
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
),
],
),
backgroundColor: Color(0xffffffff),
elevation: 1,
toolbarHeight: 40.0,
iconTheme: IconThemeData(color: Colors.grey),
),
drawer: Drawer(
child: ListView(
children: <Widget>[],
),
),
body: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
color: Color(0xfffafafa),
child: Text("hello"),
),
);
}
}
用這個包裹你的搜索按鈕將減少填充。
不確定您要刪除多少填充。
SizedBox(
width: 10.0,
child: IconButton(
padding: EdgeInsets.zero,
icon: Icon(Icons.search),
onPressed: () {},
),
),
添加此行以刪除 IconButton 的默認填充:
IconButton(
constraints: BoxConstraints(),
padding: const EdgeInsets.all(0),),
像這樣嘗試
appBar: AppBar(
title: Text(title),
backgroundColor: kPrimaryLightColor,
actions: <Widget>[
Padding(
padding: EdgeInsets.only(right: 20.0),
child: GestureDetector(
onTap: () {},
child: Icon(
Icons.message_rounded,
size: 30.0,
),
)),
解決方案 1
只需在 AppBar 標簽中添加一個名為“titleSpacing”的屬性,
樣本
appBar: AppBar(
titleSpacing: 0, //Add this line to your code
title: Text(widget.title),
leading: Icon(Icons.android),
),
解決方案 2
或者用“Transform.translate”包裝你的標題並添加屬性“offset”。
樣本
title: Transform.translate(
offset: Offset(-30.0, 0.0),
child: Text('your app title')
),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.