0

I am trying to get list of offers with fields DateTime but it returns 0 records, i tried var instead of DateTime but also return nothing when i remove these fields it works fine please if you can help, thanks

import 'package:cloud_firestore/cloud_firestore.dart';
class OfferModel{
 static const APPID = "appid";
 static const ID = "id";
 static const NAME = "name";
 static const STARTDATE = "startdate";
 static const ENDDATE = "enddate";
 static const PRODUCTS = "products";
 static const CREATEDAT = "createdat";

 String appid;
 String id;
 String name;
 DateTime startdate;
 DateTime enddate;
 List products;
 Timestamp createdat;

OfferModel();

  OfferModel.fromMap(Map<String, dynamic> data){
   appid = data[APPID];
   id = data[ID];
   name = data[NAME];
   startdate = DateTime.parse(data[STARTDATE]);
   enddate = DateTime.parse(data[ENDDATE]);
   products = data[PRODUCTS];
   createdat=data[CREATEDAT];
  }

  Map<String, dynamic> toMap() {
    return {
      APPID : appid,
      ID: id,
      NAME:name,
      STARTDATE: startdate,
      ENDDATE: enddate,
      PRODUCTS: products,
      CREATEDAT:createdat,
    };
  }
}
Hesham Elkotabi
  • 193
  • 1
  • 9
  • are you using `startdate` or `enddate` or `createdat` to sort the offers? – ByteMe Aug 10 '20 at 22:02
  • 2
    What do `data[STARTDATE]` and `data[ENDDATE]` look like? People can't help you with parsing if they don't know what the data is that you're trying to parse. https://stackoverflow.com/a/61394854/ might be helpful. – jamesdlin Aug 10 '20 at 23:02
  • I need any formate, the problem that i can't get the offers when I call query, QuerySnapshot snapshot= await Firestore.instance.collection('offers') .getDocuments(); it returns 0 records but when i remove this 2 fields it get records normally – Hesham Elkotabi Aug 15 '20 at 22:26

0 Answers0