Skip to content

Instantly share code, notes, and snippets.

@vijayinyoutube
Created June 27, 2022 18:16
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 vijayinyoutube/caf2e70d3dbb91ecd8a44bf1367bb028 to your computer and use it in GitHub Desktop.
Save vijayinyoutube/caf2e70d3dbb91ecd8a44bf1367bb028 to your computer and use it in GitHub Desktop.
class HomePageModel {
final String name;
final int? age;
HomePageModel(
this.name,
this.age,
);
HomePageModel copyWith({
String? name,
int? age,
}) {
return HomePageModel(
name ?? this.name,
age ?? this.age,
);
}
Map<String, dynamic> toMap() {
return <String, dynamic>{
'name': name,
'age': age,
};
}
factory HomePageModel.fromMap(Map<String, dynamic> map) {
return HomePageModel(
map['name'] as String,
map['age'] != null ? map['age'] as int : null,
);
}
String toJson() => json.encode(toMap());
factory HomePageModel.fromJson(String source) => HomePageModel.fromMap(json.decode(source) as Map<String, dynamic>);
@override
String toString() => 'HomePageModel(name: $name, age: $age)';
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is HomePageModel &&
other.name == name &&
other.age == age;
}
@override
int get hashCode => name.hashCode ^ age.hashCode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment