i have a model class

import 'package:cloud_firestore/cloud_firestore.dart';

class Available{
 String uid;
 DateTime date;
 int stock;
 bool isAvailable;


  Available.fromJson(Map<String, dynamic> json)
       : uid = json['UID'],
       date = DateTime.parse(json['date'].toDate().toString()),
     stock = json['stock'],
    isAvailable = json["isAvailable"];

 Map<String, dynamic> toJson() {
   return {
    'UID': uid,
    'date': date,
    'stock': stock,
    'isAvailable': isAvailable,

and i have a list of Available objects and when i try to encode the list to json and store it to firestore i can't seem to do it because of the DateTime object

Note : am updating the entire list like so :

var json = jsonEncode(value.map((e) => e.toJson()).toList(),toEncodable: myDateSerializer);


but i need all the dates for each object to be stored as firestore timestamp so using date.toIso8601String() or date.microsecondsSinceEpoch will not work as it won't be firestore timestamp format .

Solution 1: w461

At least with Firebase you can store a DateTime object directly.

I think you are doubling the json markup with your update. Just pass the date with update: update({"dates":myDate