【问题标题】:Flutter: Fixed widget and listview in one pageFlutter:固定小部件和列表视图在一页中
【发布时间】:2019-03-10 19:00:11
【问题描述】:

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

代码如下:

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


    【解决方案1】:

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

    Expanded(
                child: ListView.builder(
    
                  },
                ),
              ),
    

    【讨论】:

      【解决方案2】:

      ListView.builder内部,使用shrinkWrap: true

      【讨论】:

        猜你喜欢
        • 2018-12-29
        • 2019-03-30
        • 2021-05-12
        • 1970-01-01
        • 2018-08-23
        • 2013-03-15
        • 1970-01-01
        • 1970-01-01
        • 2021-06-16
        相关资源
        最近更新 更多