fireship.io icon indicating copy to clipboard operation
fireship.io copied to clipboard

courses/flutter-firebase/firestore-json-serializable/

Open utterances-bot opened this issue 2 years ago • 2 comments

JSON Serializable

How to use JSON Serializable with Firestore

https://fireship.io/courses/flutter-firebase/intro-flutter-create/

utterances-bot avatar Apr 02 '22 12:04 utterances-bot

Could you give me a little hint how to use for example a DateTime Field with this approach? I tried: class Test { DateTime testdate; ... Test( {this.testdate = const DateTime() , ...

Then i get "const_with_non_const - The constructor being called isn't a const constructor. Try removing 'const' from the constructor invocation."

When i try: this.testdate = DateTime() i get: "value": "non_constant_default_value", "message": "The default value of an optional parameter must be constant.", "value": "not_enough_positional_arguments", "message": "1 positional argument(s) expected, but 0 found.\nTry adding the missing arguments.",

I even tried DateTime.now() but still get errors.

OberstVonGatow avatar Apr 02 '22 12:04 OberstVonGatow

As of August, 2022, the command should be

flutter pub run build_runner build

The versions that work for me are

  json_annotation: 4.6.0
  build_runner: 2.2.0
  json_serializable: 6.3.1

rongpenl avatar Aug 21 '22 18:08 rongpenl