Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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