- 将
leading
设置为null
- 将
automaticallyImplyLeading
设置为false
看看automaticallyImplyLeading
的说明:
Controls whether we should try to imply the leading widget if null.
If true and [AppBar.leading] is null, automatically try to deduce what the leading widget should be. If false and [AppBar.leading] is null, leading space is given to [AppBar.title]. If leading widget is not null, this parameter has no effect.
意思就是说:
- 如果
leading
为null 并且automaticallyImplyLeading
为true , 那么会保留leading
的占位位置;- 如果如果
leading
为null 并且automaticallyImplyLeading
为false , 那么会将leading
的位置让给title;- 如果
leading
不为null ,automaticallyImplyLeading
这个设置失效。
代码如下:
build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: null,
automaticallyImplyLeading: false,
title: Container(
margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
height: Screenadapter.height(100),
width: Screenadapter.width(880) ,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Color.fromARGB(10, 0, 0, 0)
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(padding: EdgeInsets.fromLTRB(10, 0, 0, 0), child: Icon(Icons.search, color: Colors.black26)),
Expanded(child: Text("耳机", style: TextStyle(color: Colors.black45, fontSize: Screenadapter.fontSize(36)))),
Padding(padding: EdgeInsets.fromLTRB(0, 0, 10, 0), child: Icon(FangXMIcon.saomiao, color: Colors.black26)),
],
),
),
centerTitle: true,
actions: [
Container(
padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
width: Screenadapter.width(124),
height: Screenadapter.height(100),
child: InkWell(
child: Icon(FangXMIcon.xiaoxi, color: Colors.black54 ),
),
)
],
),
body: const Center(
child: Text(
'GiveView is working',
style: TextStyle(fontSize: 20),
),
),
);
}
Widget
效果如下: