Skip to content

Instantly share code, notes, and snippets.

Created June 27, 2022 18:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
class HomePageModel {
final String name;
final int? age;
HomePageModel copyWith({
String? name,
int? age,
}) {
return HomePageModel(
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>);
String toString() => 'HomePageModel(name: $name, age: $age)';
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is HomePageModel && == name &&
other.age == age;
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