FirebaseExtended / firestoreodm-flutter

BSD 3-Clause "New" or "Revised" License
33 stars 9 forks source link

Format exception on model using Timestamp #8

Closed usman092 closed 5 months ago

usman092 commented 5 months ago

I have a model with a Timestamp field.

@firestoreSerializable
class Model {
  final Timestamp time;
  Model({required this.time});

  factory Model.fromJson(Map<String, Object?> json) => _$ModelFromJson(json);

  Map<String, Object?> toJson() => _$ModelToJson(this);

  Future<Model> put() async {
    return await modelsRef.doc('someId').set(this);
  }

I am setting the field value using Timestamp.fromDate(DateTime.parse('2016-02-11')) However, when I call the put method I get the following exception

FormatException: Invalid date format
2016-2-11

Expected Behavior

Exception should not occur.

Actual Behavior

Model should be successfully saved to firestore.

Steps to Reproduce the Problem

  1. Define the model
  2. Create an object
  3. Call the put method

Specifications