【发布时间】:2020-04-28 22:01:50
【问题描述】:
如何将现有值映射到 Flutter 动态表?
以下是我现有的工作代码。正在使用 json 打印值。我想将那些现有值打印到表中并最终按列对它们进行排序。 注意: Flutter 新手,感谢您的帮助。
class PhotosList extends StatelessWidget {
final List<Photo> photos;
PhotosList({Key key, this.photos}) : super(key: key);
@override
Widget build(BuildContext context) {
return GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
itemCount: photos.length,
itemBuilder: (context, index) {
return ListTile(
// leading: Icon(Icons.album),
title: Column( children: [
Text(photos[index].symbol),
Padding(padding: EdgeInsets.only(bottom: 10.0)),
//Text(photos[index].companyName),
],
),
subtitle: Column(
children: [
Text ('${photos[index].data["quote"]["companyName"] ?? ""}'),
Text ("Dividend Yield:" '${photos[index].data["stats"]["dividendYield"] ?? ""}'),
Text ("Last Price:" '${photos[index].data["quote"]["iexBidPrice"]?? ""}'),
Text ("Last Price:" '${photos[index].data["stats"]["latestPrice"]?? ""}'),
//
],
),
);
},
);
}
}
数据表: 来自:https://github.com/iampawan/FlutterWidgets/blob/master/lib/Episode5_DataTable/datatable_example.dart
Widget bodyData() => DataTable(
onSelectAll: (b) {},
sortColumnIndex: 1,
sortAscending: true,
columns: <DataColumn>[
DataColumn(
label: Text("First Name"),
numeric: false,
onSort: (i, b) {
print("$i $b");
setState(() {
names.sort((a, b) => a.firstName.compareTo(b.firstName));
});
},
tooltip: "To display first name of the Name",
),
DataColumn(
label: Text("Last Name"),
numeric: false,
onSort: (i, b) {
print("$i $b");
setState(() {
names.sort((a, b) => a.lastName.compareTo(b.lastName));
});
},
tooltip: "To display last name of the Name",
),
],
rows: names
.map(
(name) => DataRow(
cells: [
DataCell(
Text(name.firstName),
showEditIcon: false,
placeholder: false,
),
DataCell(
Text(name.lastName),
showEditIcon: false,
placeholder: false,
)
],
),
)
.toList());
https://material.io/components/data-tables/#
谢谢! ???
【问题讨论】:
-
@chunhunghan chunhunghan 求助!
-
您似乎没有提出问题或需要帮助解决编码问题。看起来您希望有人为您实现代码。我建议您查看问题指南:stackoverflow.com/help/how-to-ask - PS:当您自 2018 年以来一直在询问有关 Flutter 的问题时,我不确定您为什么说您是 Flutter 新手。