Flutter:在一个页面中修复了widget和listview

问题描述 投票:0回答:2

我在Flutter做了一个项目,我有一个Dropdownmenu,在菜单下,我会有一个listview,但是我收到了一个错误。但是当我只有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:
flutter flutter-layout
2个回答
0
投票

ListView.builder内部,使用shrinkWrap: true


0
投票

将你的ListView包裹在Expanded小部件中

Expanded(
            child: ListView.builder(

              },
            ),
          ),
© www.soinside.com 2019 - 2024. All rights reserved.