AlertCardWidget 是我编写的一个小部件。我在 itemBuilder 中返回它但没有显示。这是我的代码:
Flexible(
child: Padding(
child: SingleChildScrollView(
child: ListView.builder(
itemCount: state.data.length,
itemBuilder: (BuildContext context, int index) {
state.data["datas"].map<Widget>((f) {
return AlertCardWidget(
positionId: "${f["8020074"]}",
shipowner: "${f["8020076"]}",
customer: "${f["8020170"]}",
salesRepresenter: "${f["8020176"]}",
operationRepresenter: "${f["8020177"]}",
textContentFontColor:
AppTheme(Theme.of(context).brightness)
.cardFontBackgroundColor,
textfont: Colors.redAccent,
);
}).toList();
},
),
),
),
),
没有错误显示。
最佳答案
我有我使用 ListView
的项目。使用 Listview
而不是 ListView.builder
的问题是“垂直视口(viewport)被赋予无限高度错误”。在编写 Listview
之类的 Expanded
小部件时,问题已解决。这是我的代码:
Expanded(
child: Padding(
padding: const EdgeInsets.all(4.0),
child: ListView(
children: state.data["datas"].map<Widget>((f) => AlertCardWidget(positionId: "${f["8020074"]}",
shipowner: "${f["8020076"]}",
customer: "${f["8020170"]}",
salesRepresenter: "${f["8020176"]}",
operationRepresenter: "${f["8020177"]}",
textContentFontColor: AppTheme(Theme.of(context).brightness).cardFontBackgroundColor,
textfont: Colors.redAccent,)).toList(),
),
),
),
关于flutter - ListView.builder 显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56252157/