Flutter:在一页中修复了小部件和列表视图

Flutter: Fixed widget and listview in one page

我在 Flutter 中创建了一个项目,其中有一个下拉菜单,在菜单下,我将有一个列表视图,但出现错误。但是当我只有 listview 或 Dropdownmenu 时它可以工作但不能同时工作。

代码如下:

class _ListViewRound extends State<ListViewRound> {
  String dropdownValue = 'Runde 1';

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        DropdownButton<String>(
          value: dropdownValue,
          onChanged: (String newValue) {
            setState(() {
              dropdownValue = newValue;
            });
          },
          items: <String>['Runde 1','Runde 2','Runde 3','Runde 4','Runde 5','Runde 6','Runde 7'] 
              .map<DropdownMenuItem<String>>((String value) {
            return DropdownMenuItem<String>(
              value: value,
              child: Text(value),
            );
          }).toList(),
        ),
        Container(
          child: ListView.builder(
            itemCount: playID.length,
            itemBuilder: (BuildContext context, int index) {
              return ListTile(
                title: Text(firstPlayer[index] + '-' + secondPlayer[index]),
                onTap: () {
                  showSnackBar(context, playID[index]);
                },
              );
            },
          ),
        ),
      ],
    );
  }

这是错误:

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

ListView.builder 内,使用 shrinkWrap: true

将您的 ListView 包装在 Expanded 小部件中

Expanded(
            child: ListView.builder(

              },
            ),
          ),