Last active
November 5, 2022 03:44
-
-
Save MelbourneDeveloper/71f9a8ffa6e5605078706df8b61a12f6 to your computer and use it in GitHub Desktop.
Freezed Person
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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