我正在尝试制作一个自动完成/预先输入的小部件。我希望将结果放置在绝对位置,并尝试通过堆栈来实现这一目标,但是我得到了RenderStack object was given an infinite size during layout.
保存前面类型的窗口小部件的父窗口小部件
@override
Widget build(BuildContext context) {
return Container(
color: Colors.lightBlue,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: Center(
child: Text('Add Items'),
),
)
],
),
Text('SELECTED ITEM: ' + (selectedIngredient != null ? item.name : 'none')),
TypeAhead(
hint: 'Enter item name',
items: items,
onClick: itemSelected,
defaultItem: defaultItem,
)
],
)
);
}
提前输入小部件:
@override
Widget build(BuildContext context) {
Widget list = matchingItems != null && matchingItems.length > 0 ? (Flexible(child:ListView.builder(
shrinkWrap: true,
itemCount: matchingItems.length,
itemBuilder: (context, index) {
...
},
),)) : Container( height: 0,);
return Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Column(
children: <Widget>[
InputText(
controller: searchController,
hint: widget.hint,
onChange: search,
),
Stack(
children: <Widget>[
Positioned(
top: 0,
left: 0,
child: Container(
height: 500,
child: list
),
)
],
)
],
)
);
}
如何使用堆栈来绝对定位单个小部件?