Flutter JSON Serialization - Not generating *.g.dart files

后端 未结 4 594
南笙
南笙 2021-01-12 23:18

I am new to flutter and the objective is to serialise complex JSON objects which contain other smaller objects.

Using the json_serializable: ^2.0.0 and

4条回答
  •  旧巷少年郎
    2021-01-12 23:52

    The constructor's argument shouldn't be optional

    User({this.firstName, this.lastName, this.dateOfBirth});
    

    They should be obligatory:

    User(this.firstName, this.lastName, this.dateOfBirth);
    

    And the part

    'user.g.dart';
    

    should be matching the Uppercase User class:

    part 'User.g.dart';
    

提交回复
热议问题