简体   繁体   English

我该如何处理动态列表 <DataColumn> 小部件,以避免Flutter DataTable小部件中的RenderFlex异常?

[英]How do I handle dynamic list of <DataColumn> Widgets to avoid RenderFlex exceptions in Flutter DataTable Widget?

I have a flutter DataTable (in a Container) that is constructed dynamically (values read from API). 我有一个颤动的DataTable(位于容器中),它是动态构造的(从API读取的值)。

Specifically, when it pulls in the columns it throws a RenderFlex exception. 具体来说,当它拉入列时,将引发RenderFlex异常。 The same values used statically pose no problem. 静态使用的相同值没有问题。

Widget bodyData() => DataTable(
  columns: colWidgets, // set in setState() function 
  rows: rowWidgets // set in setState() function ,
);

...

colWidgets = ListofValues.map((value){
  return new DataColumn(
    label: Text(value)
  );
}).toList();

What is the best way to prepare the DataTable for these values via something like Padding or SingleScrollView? 通过Padding或SingleScrollView等为这些值准备DataTable的最佳方法是什么?

I was able to solve this by moving the DataColumn widgets into a FittedBox widget within a Column widget. 通过将DataColumn小部件移动到Column小部件内的FittedBox小部件中,我能够解决此问题。 The key thing is that the parent/ancestor must have a flex property which the Column provides. 关键是父/祖先必须具有Column提供的flex属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Renderflex 溢出 - 我如何在 flutter 中克服这个问题? - Renderflex overflow - how do I overcome this in flutter? 如何在 Flutter DataColumn 小部件中将标签居中? - How do you center the label in a Flutter DataColumn widget? 如何删除小部件并将其添加到小部件的动态列表中 - How to delete and add widget to dynamic list of Widgets 我如何开启未来<list>从 Firestore 到带有 Flutter 的小部件?</list> - How do I turn a Future <List> from Firestore into widgets with Flutter? 如何在Flutter中的列表之前和/或之后添加小部件 - how do I add widgets before and/or after a list in flutter 颤动:在状态窗口小部件中使用状态窗口小部件数组导致&#39;A RenderFlex溢出&#39; - Flutter: Using an array of Stateful Widgets inside a Stateful Widget causes a 'A RenderFlex overflow' Flutter:当小部件没有父/子关系时,如何从小部件 B 调用小部件 A 中的 function? - Flutter: How do I call a function in widget A from widget B when the widgets do not have a parent/child relationship? 如何在颤振中处理这些异常? - How to handle this exceptions in flutter? 如何使长文本水平滚动以避免Flutter中的Renderflex溢出 - How to make a long text horizontally scrollable to avoid Renderflex overflow in Flutter 如何使小部件在 Flutter 中可重用? - How do I make widgets reusable in Flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM