如何在 flutter web 中将 AppBar 内容居中
How to centered AppBar content in flutter web
我试图在 flutter web 中将整个 appBar 内容居中,就像 appBar 下方的占位符一样。我想把应用栏做成下图这样
这是我的小部件状态的代码
class _LoginState extends State<Login> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: false,
titleSpacing: 0.0,
title: const Text(
'Title',
),
automaticallyImplyLeading: true,
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () {
Navigator.pop(
context,
MaterialPageRoute(
builder: (BuildContext context) => Intro()));
}),
backgroundColor: Theme.of(context).primaryColor,
),
backgroundColor: Theme.of(context).canvasColor,
body: Center(
child: AspectRatio(
aspectRatio: 9 / 16,
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Placeholder(),
),
),
),
);
}
}
尝试自定义应用栏
AppBar(
centerTitle: true,
titleSpacing: 0.0,
title: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(icon: Icon(Icons.arrow_back_ios), onPressed: () {}),
const Text('Title'),
],
),
backgroundColor: Theme.of(context).primaryColor,
),
我试图在 flutter web 中将整个 appBar 内容居中,就像 appBar 下方的占位符一样。我想把应用栏做成下图这样
这是我的小部件状态的代码
class _LoginState extends State<Login> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: false,
titleSpacing: 0.0,
title: const Text(
'Title',
),
automaticallyImplyLeading: true,
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () {
Navigator.pop(
context,
MaterialPageRoute(
builder: (BuildContext context) => Intro()));
}),
backgroundColor: Theme.of(context).primaryColor,
),
backgroundColor: Theme.of(context).canvasColor,
body: Center(
child: AspectRatio(
aspectRatio: 9 / 16,
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Placeholder(),
),
),
),
);
}
}
尝试自定义应用栏
AppBar(
centerTitle: true,
titleSpacing: 0.0,
title: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(icon: Icon(Icons.arrow_back_ios), onPressed: () {}),
const Text('Title'),
],
),
backgroundColor: Theme.of(context).primaryColor,
),