-1

Here is my model and I wanna store this data in a list ,using getx .null safety method is on.

    var productlist = <Productmodel>[].obs;


  Productmodel.frommap( DocumentSnapshot snapshot) {
        id = snapshot['id'];
        productname = snapshot['name'];
        price = snapshot['price'];
        image = snapshot['image'];
        brand = snapshot['brand'];
      }

data in firebase database is shown here

General Grievance
  • 4,555
  • 31
  • 31
  • 45

2 Answers2

0

In this way, you can access the data by giving the names collection and field.

Example

  • i wanna store the data in a list in a controller file ,in view file i will just call the list and using listviewbuilder i will display the list. – hahah i am coder Sep 29 '22 at 19:56
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 04 '22 at 12:47
0

try this method...

Future<void> getAllData() async {
   List<Productmodel> productModelList = [];

   var data = await FirebaseFirestore.instance.collection("product").doc('CWvaDGh5ZaCznGtLnq6A').get();
   List dataList = data.data()?['product'];
   
   for (var element in dataList) {
     productModelList.add(Productmodel.fromJson(element));
   }

  print('productModelList : ${productModelList.toList()}');
}