In code, code fetches data in a real-time(stream) manner from cloud firestore and shows it in the data-table widget using StreamBuilder, but when I run the code it gives the error as I asked above.
SizedBox(
width: double.infinity,
child: StreamBuilder(
stream: FirebaseFirestore.instance.collection('products').snapshots(),
builder: (BuildContext context,snapshot) {
(!snapshot.hasData)?
Center(child: CircularProgressIndicator())
: DataTable(
// columnSpacing: defaultPadding,
columns: [
DataColumn(label: Text("Id")),
DataColumn(label: Text("Name")),
DataColumn(label: Text("Category")),
DataColumn(label: Text("Image")),
DataColumn(label: Text("Original Price")),
DataColumn(label: Text("Sale Price")),
DataColumn(label: Text("Discount")),
DataColumn(label: Text("Commission")),
DataColumn(label: Text("Date")),
],
rows: _listofRows(snapshot.data),
);
})),
_listofRows method code here
List<DataRow> _listofRows(snapshot) {
List<DataRow> newList = snapshot.docs.map((docSnapshot) {
return DataRow(cells: <DataCell>[
DataCell(Text(docSnapshot.data()['ProductID'].toString())),
DataCell(Text(docSnapshot.data()['Product Name'].toString())),
DataCell(Text(docSnapshot.data()['Category Name'].toString())),
DataCell(Text(docSnapshot.data()['Product ImageUrl'].toString())),
DataCell(Text(docSnapshot.data()['originalPrice'].toString())),
DataCell(Text(docSnapshot.data()['salePrice'].toString())),
DataCell(Text(docSnapshot.data()['Discount'].toString())),
DataCell(Text(docSnapshot.data()['Commission Rate'].toString())),
DataCell(Text(doctSnapshot.data()['Out of Stock Date'].toString())),
]);
}).toList();
return newList;
}