我有一个应用程序栏,我想要在其中显示标题,然后在它旁边有一个凸起的按钮,该按钮会扩展以填充剩余的水平空间。我尝试了以下变体:
AppBar(
title: Row(
children: [
Text("Select view"),
// the row that follows is because it says Expanded widgets
// should be put directly in Row or Column or Flex
Padding(padding: EdgeInsets.only(left: 12.0), child: Row(children: [
Expanded(child: RaisedButton(
child: Text("view 1"),
onPressed: () {
// something
},
),),
])),
]
),
);
为此,我收到以下错误:
I/flutter (26477): The following assertion was thrown during performLayout():
I/flutter (26477): The _ToolbarLayout custom multichild layout delegate forgot to lay out the following children:
I/flutter (26477): _ToolbarSlot.middle: RenderSemanticsAnnotations#6d937 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26477): _ToolbarSlot.middle: RenderSemanticsAnnotations#7fcd5 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26477): _ToolbarSlot.middle: RenderSemanticsAnnotations#f9a7a NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26477): _ToolbarSlot.middle: RenderSemanticsAnnotations#ce1f2 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26477): Each child must be laid out exactly once.
我尝试过的所有其他事情也引发了一些断言异常。我并不关心如何做到这一点,我只想有两个小部件 - 标题和它旁边的一个 RaishedButton
,它填充应用栏中的其余空间。
最佳答案
只需删除包含 RaishedButton
的行
appBar: AppBar(
title: Row(children: [
Text("Select view"),
Expanded(
child: RaisedButton(
child: Text("view 1"),
onPressed: () {
// something
},
),
),
]),
),
关于flutter - AppBar 中的扩展小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55078683/