How to map existing values to a Flutter Dynamic Table?
The following is my existing working code. is using json to print the values. those existing values I would like to print to a table and eventually sort them by columns. Note: New to Flutter and I appreciate your assistance.
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"]?? ""}'),
//
],
),
);
},
);
}
}
Data Table: from: 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/#
Thank you! 😊
