Skip to content

Instantly share code, notes, and snippets.

@MelbourneDeveloper
Last active November 5, 2022 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MelbourneDeveloper/71f9a8ffa6e5605078706df8b61a12f6 to your computer and use it in GitHub Desktop.
Save MelbourneDeveloper/71f9a8ffa6e5605078706df8b61a12f6 to your computer and use it in GitHub Desktop.
Freezed Person
//Manually Entered Code
@freezed
class Person with _$Person {
const factory Person({
required String firstName,
required String lastName,
required List<int> numbers,
required int age,
}) = _Person;
factory Person.fromJson(Map<String, Object?> json) => _$PersonFromJson(json);
}
//Some of the generated code from the tool
class _$_Person implements _Person {
const _$_Person(
{required this.firstName,
required this.lastName,
required final List<int> numbers,
required this.age})
: _numbers = numbers;
factory _$_Person.fromJson(Map<String, dynamic> json) =>
_$$_PersonFromJson(json);
@override
final String firstName;
@override
final String lastName;
final List<int> _numbers;
@override
List<int> get numbers {
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_numbers);
}
@override
final int age;
@override
String toString() {
return 'Person(firstName: $firstName, lastName: $lastName, numbers: $numbers, age: $age)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_Person &&
(identical(other.firstName, firstName) ||
other.firstName == firstName) &&
(identical(other.lastName, lastName) ||
other.lastName == lastName) &&
const DeepCollectionEquality().equals(other._numbers, _numbers) &&
(identical(other.age, age) || other.age == age));
}
@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, firstName, lastName,
const DeepCollectionEquality().hash(_numbers), age);
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$_PersonCopyWith<_$_Person> get copyWith =>
__$$_PersonCopyWithImpl<_$_Person>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$_PersonToJson(
this,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment