Я пытаюсь настроить страницу поиска в приложении Flutter.Этот виджет представляет поле поиска, отслеживает, что печатает пользователь, и обновляет список предлагаемых совпадений при каждом изменении в поле поиска.Соответствующий фрагмент приведен здесь:
List<Text> suggestList = [new Text('')];
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
new Form(
child: new TextFormField(
// _controller listens for changes and updates suggestList
controller: _controller,
autocorrect: false,
decoration: InputDecoration(labelText: 'Search here'),
onSaved: (str) => print(str),
),
),
new ListView.builder(
itemBuilder: (context, index) => suggestList[index],
itemCount: suggestList.length,
)
],
);
}
Этот виджет аварийно завершает работу с сообщением об ошибке длиной в несколько страниц, но включает в себя этот текст, указывающий на то, что моя ошибка связана с макетом.Я новичок в Flutter и Dart и не могу по-настоящему применить приведенный здесь совет к моей проблеме.
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during performResize():
Vertical viewport was given unbounded height.
Viewports expand in the scrolling direction to fill their container.
In this case, a vertical
viewport was given an unlimited amount of vertical space in which to expand.
This situation
typically happens when a scrollable widget is nested inside another
scrollable widget.
If this widget is always nested in a scrollable widget there is no
need to use a viewport because
there will always be enough vertical space for the children.
In this case, consider using a Column
instead. Otherwise, consider using the "shrinkWrap" property
(or a ShrinkWrappingViewport) to size
the height of the viewport to the sum of the heights of its children.
В следующем фрагменте я пытаюсь смоделировать нужный эффект, представив последовательность виджетов Text:
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
new Form(
child: new TextFormField(
controller: _controller,
autocorrect: false,
decoration: InputDecoration(labelText: 'Search here'),
onSaved: (str) => print(str),
),
),
// Present the two first items manually as Text widgets
suggestList[0],
suggestList.length > 1 ? suggestList[1] : new Text('...'),
],
);
}
Это отлично работает, но выглядит некрасиво и явно является взломом, который мне не нужен в финальном приложении.Также я подтвердил, что моя логика работает отлично - я проверил, что suggestList
всегда заполнен хотя бы одним виджетом Text
, подходящим для отображения.Любые идеи о том, как восстановить подход ListView?