您也可以使用填充来对齐。
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
bool _showConnecting = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// 24 for default icon size
toolbarHeight: _showConnecting ? kToolbarHeight + 24 : kToolbarHeight,
centerTitle: false,
leadingWidth: 0,
titleSpacing: 0,
automaticallyImplyLeading: false,
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
if (_showConnecting)
Container(
color: Colors.black,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.network_cell_sharp),
Text("Connecting.."),
],
),
),
Container(
height: kToolbarHeight,
alignment: Alignment(-.8, 0),
color: Theme.of(context).primaryColor,
child: Text("Recent Mentions"),
),
],
),
),
body: SingleChildScrollView(
child: Column(
children: [
...List.generate(
44,
(index) => Container(
height: 100,
color: index.isEven ? Colors.amber : Colors.cyanAccent,
),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
_showConnecting = !_showConnecting;
});
},
),
);
}}