具有ListView的AnimatedCrossFade出现了无界高度错误

时间:2018-08-25 03:54:54

标签: dart flutter

这是代码。我想要的是在请求结果时显示进度,而在请求完成时将结果显示为列表。

我选择AnimatedCrossFade,因为它具有方便的过渡动画;

Widget SearchResultPage() {
    return AnimatedCrossFade(
        firstChild: Center(
          child: CircularProgressIndicator(),
        ),
        secondChild: ListView.builder(
            itemCount: _searchResult.length,
            itemBuilder: (BuildContext context, int index) {
              return SearchListItem(_searchResult[index]);
            }),
        crossFadeState: _searchResult.isEmpty
            ? CrossFadeState.showFirst
            : CrossFadeState.showSecond,
        duration: Duration(milliseconds: 500));
  }


 Widget SearchListItem(BookFuzzySearchDetail detail) {
    return Container(
      decoration:
          BoxDecoration(border: Border(bottom: BorderSide(color: Colors.grey))),
      child: ListTile(
        contentPadding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 4.0),
        leading: Image.network(
          detail.cover,
          width: 50.0,
          height: 50.0,
        ),
        title: Text(
          detail.title,
        ),     
      ),
    );
  }

我得到了错误:

I/flutter ( 6281): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 6281): The following assertion was thrown during performResize():
I/flutter ( 6281): Vertical viewport was given unbounded height.
I/flutter ( 6281): Viewports expand in the scrolling direction to fill their container.In this case, a vertical
I/flutter ( 6281): viewport was given an unlimited amount of vertical space in which to expand. This situation
I/flutter ( 6281): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter ( 6281): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter ( 6281): there will always be enough vertical space for the children. In this case, consider using a Column
I/flutter ( 6281): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
I/flutter ( 6281): the height of the viewport to the sum of the heights of its children.

新手入门,在这里呆了几天,请多多指教。

1 个答案:

答案 0 :(得分:0)

尝试将属性shrinkWrap添加到您的ListView.builder

        ListView.builder(
                    shrinkWrap: true,
                    itemCount: _searchResult.length,
                    itemBuilder: (BuildContext context, int index) {
                      return SearchListItem(_searchResult[index]);
                    }),