AppBar 中的 Flutter 居中文本
Flutter Centering text in AppBar
我只是想让整个文本居中(当然它应该还在 AppBar 中)。感谢
appBar: AppBar(
toolbarHeight: 80.0,
backgroundColor: Colors.amber,
title: Row(children: [
Text("Text",
style: GoogleFonts.josefinSans(
textStyle: const TextStyle(fontSize: 40.0))),
Text(
"The Game",
style: GoogleFonts.overpass(
textStyle: const TextStyle(fontSize: 20.0)),
)
])),
使用 centerTitle : true
appBar: AppBar(
centerTitle: true,
toolbarHeight: 80.0,
backgroundColor: Colors.amber,
title: Row(children: [
Text("Text",
style: GoogleFonts.josefinSans(
textStyle: const TextStyle(fontSize: 40.0))),
Text(
"The Game",
style: GoogleFonts.overpass(
textStyle: const TextStyle(fontSize: 20.0)),
)
])),
在 Row
小部件中包含 mainAxisAlignment
到 MainAxisAlignment.center
示例代码:
AppBar(
toolbarHeight: 80.0,
backgroundColor: Colors.amber,
title: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Text("Text",
style: GoogleFonts.josefinSans(
textStyle: const TextStyle(fontSize: 40.0))),
Text(
"The Game",
style: GoogleFonts.overpass(
textStyle: const TextStyle(fontSize: 20.0)),
)
]))
我只是想让整个文本居中(当然它应该还在 AppBar 中)。感谢
appBar: AppBar(
toolbarHeight: 80.0,
backgroundColor: Colors.amber,
title: Row(children: [
Text("Text",
style: GoogleFonts.josefinSans(
textStyle: const TextStyle(fontSize: 40.0))),
Text(
"The Game",
style: GoogleFonts.overpass(
textStyle: const TextStyle(fontSize: 20.0)),
)
])),
使用 centerTitle : true
appBar: AppBar(
centerTitle: true,
toolbarHeight: 80.0,
backgroundColor: Colors.amber,
title: Row(children: [
Text("Text",
style: GoogleFonts.josefinSans(
textStyle: const TextStyle(fontSize: 40.0))),
Text(
"The Game",
style: GoogleFonts.overpass(
textStyle: const TextStyle(fontSize: 20.0)),
)
])),
在 Row
小部件中包含 mainAxisAlignment
到 MainAxisAlignment.center
示例代码:
AppBar(
toolbarHeight: 80.0,
backgroundColor: Colors.amber,
title: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Text("Text",
style: GoogleFonts.josefinSans(
textStyle: const TextStyle(fontSize: 40.0))),
Text(
"The Game",
style: GoogleFonts.overpass(
textStyle: const TextStyle(fontSize: 20.0)),
)
]))