【发布时间】:2020-07-07 08:02:21
【问题描述】:
在 Flutter 中我想创建一个如下所示的应用栏:
我很容易设法在左右两侧添加了 2 个图标,但我很难在中间创建一个矩形。
我试过以下代码:
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
leading: IconButton(
icon: Image.asset('assets/images/maps.png'),
onPressed: () => {},
),
title: Expanded( // The bit that's not working. A rectangle that fills the middle area.
child: Container(
color: Colors.blue,
),
),
actions: <Widget>[
IconButton(
icon: Image.asset('assets/images/search.png'),
onPressed: () => {},
),
],
),
);
但我得到以下异常:
Expanded widgets must be placed inside Flex widgets.
Expanded(no depth, flex: 1, dirty) has no Flex ancestor at all.
感谢您的帮助。
【问题讨论】: