【问题标题】:How to arrange scrollable layout for list of widgets in flutter?如何为颤动的小部件列表安排可滚动布局?
【发布时间】:2022-11-14 13:18:29
【问题描述】:

我想构建一个可滚动的小部件,该小部件由函数生成的一些 Text 小部件(可能还有其他一些小部件)组成。但是,我收到以下错误:

一个 RenderFlex 在底部溢出了 701 个像素。

我不确定这里最好的布局是什么。可滚动的 Column 是否应该放在容器之外?是否需要最内层嵌套的列?是否需要另一个扩展小部件?

此外,小部件列表中的文本应左对齐,而不是居中。 如果有人可以提供有用的解决方案,我将非常感激!

这是我当前的代码:

List<Widget> getWidgetList(){
// do some stuff and return a list
return [Text("foo"), Text("bar")];
}

@override
Widget build(BuildContext context) => Scaffold(... body:
      Container(
          padding: EdgeInsets.all(20),
          child:
          SingleChildScrollView(
              scrollDirection: Axis.vertical,
              child:
              SizedBox(
                  height: MediaQuery.of(context).size.height,
                  child:
                  Column(
                      children: getWidgetList()
                  )
              )
          )
      )
    );
}

【问题讨论】:

    标签: android ios flutter dart


    【解决方案1】:

    我认为溢出发生在getWidgetList。去掉SizedBox的固定高度,

       Container(
              padding: EdgeInsets.all(20),
              child:
              SingleChildScrollView(
                  scrollDirection: Axis.vertical,
                  child:
                  SizedBox(
                     // height: MediaQuery.of(context).size.height,
                      child:
                      Column(
                          children: getWidgetList()
                      )
                  )
              )
          )
        );
    

    【讨论】:

      猜你喜欢
      • 2019-05-23
      • 1970-01-01
      • 2014-08-12
      • 2021-03-03
      • 1970-01-01
      • 2020-08-02
      • 2023-01-19
      • 1970-01-01
      • 2022-12-16
      相关资源
      最近更新 更多