Extending auto-generated Amplify Datastore classes with factory constructors

0 votes

The base model generated through AWS Amplify Studio:

@immutable
class Patient extends Model {
  static const classType = const _PatientModelType();
  final String id;
  final String? _name;
  final String? _family_name;
  final TemporalDate? _dob;
  final Gender? _gender;
  final double? _height_in_inches;
  final List<Assessment>? _Assessments;
  final TemporalDateTime? _createdAt;
  final TemporalDateTime? _updatedAt;

 ...
  
  const Patient._internal({required this.id, required name, required family_name, required dob, required gender, required height_in_inches, Assessments, createdAt, updatedAt}): _name = name, _family_name = family_name, _dob = dob, _gender = gender, _height_in_inches = height_in_inches, _Assessments = Assessments, _createdAt = createdAt, _updatedAt = updatedAt;
  
  factory Patient({String? id, required String name, required String family_name, required TemporalDate dob, required Gender gender, required double height_in_inches, List<Assessment>? Assessments}) {
    return Patient._internal(
      id: id == null ? UUID.getUUID() : id,
      name: name,
      family_name: family_name,
      dob: dob,
      gender: gender,
      height_in_inches: height_in_inches,
      Assessments: Assessments != null ? List<Assessment>.unmodifiable(Assessments) : Assessments);
  }
  
  ...
  
  Patient.fromJson(Map<String, dynamic> json)  
    : id = json['id'],
      _name = json['name'],
      _family_name = json['family_name'],
      _dob = json['dob'] != null ? TemporalDate.fromString(json['dob']) : null,
      _gender = enumFromString<Gender>(json['gender'], Gender.values),
      _height_in_inches = (json['height_in_inches'] as num?)?.toDouble(),
      _Assessments = json['Assessments'] is List
        ? (json['Assessments'] as List)
          .where((e) => e?['serializedData'] != null)
          .map((e) => Assessment.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
          .toList()
        : null,
      _createdAt = json['createdAt'] != null ? TemporalDateTime.fromString(json['createdAt']) : null,
      _updatedAt = json['updatedAt'] != null ? TemporalDateTime.fromString(json['updatedAt']) : null;
  
  ...
}

I want to create an extension class GaitPatient. But, I am running into this error,

I am currently looking at using Patient.fromJSON constructor, but a bit hesitant about using that because it doesn't seem to be the cleanest... what are my options here?

Feb 16 in AWS by Ashwini
• 3,750 points
50 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In AWS

+1 vote
5 answers

Can Celery be used with Amazon SQS

I regenerated the credentials in the IAM ...READ MORE

answered Oct 25, 2018 in AWS by triedntested
2,763 views
+1 vote
10 answers
+1 vote
2 answers

Starting with an AWS Instance with API and AUTHPARAMS

The API is usually much easier to ...READ MORE

answered Apr 17, 2018 in AWS by Cloud gunner
• 4,660 points
2,820 views
0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer

What is the difference between functions and classes to create reusable widgets?

In Flutter, you can create reusable widgets ...READ MORE

answered 2 days ago in Flutter by vinayak
24 views
0 votes
1 answer

Python class inherits object

Python 3.x: class MyClass(object): = new-style class class MyClass: = new-style ...READ MORE

answered Aug 30, 2018 in Python by Priyaj
• 58,100 points
348 views
0 votes
1 answer

Dart_LoadScriptFromKernel: The binary program does not contain 'main'.

Hi@akhtar, You need to add the main() function ...READ MORE

answered Jul 21, 2020 in Others by MD
• 95,460 points
2,614 views
0 votes
1 answer

How to install Dart in Windows system?

Hi@akhtar, Dart is the programming language used to code Flutter apps. ...READ MORE

answered Jul 21, 2020 in Others by MD
• 95,460 points
527 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP