Skip to content

Instantly share code, notes, and snippets.

@RedBrogdon
Created August 1, 2018 17:31
Show Gist options
  • Save RedBrogdon/19f1ca02d310586499b9ef85744ea406 to your computer and use it in GitHub Desktop.
Save RedBrogdon/19f1ca02d310586499b9ef85744ea406 to your computer and use it in GitHub Desktop.
class SimpleObject {
const SimpleObject({
this.aString,
this.anInt,
this.aDouble,
this.aListOfStrings,
this.aListOfInts,
this.aListOfDoubles,
});
final String aString;
final int anInt;
final double aDouble;
final List<String> aListOfStrings;
final List<int> aListOfInts;
final List<double> aListOfDoubles;
factory SimpleObject.fromJson(Map<String, dynamic> json) {
if (json == null) {
throw FormatException("Null JSON provided to SimpleObject");
}
return SimpleObject(
aString: json['aString'],
anInt: json['anInt'],
aDouble: json['aDouble'],
aListOfStrings: json['aListOfStrings'] != null
? List<String>.from(json['aListOfStrings'])
: null,
aListOfInts: json['aListOfInts'] != null
? List<int>.from(json['aListOfInts'])
: null,
aListOfDoubles: json['aListOfDoubles'] != null
? List<double>.from(json['aListOfDoubles'])
: null,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment