import 'dart:convert'; abstract class BaseModel { BaseModel(); Map toMap(); T fromMap(Map map); T fromJson(String json) { return fromMap(decode(json)); } @override String toString() { return toMap().toString(); } @override bool operator ==(Object other) { if (identical(this, other)) return true; return other is BaseModel && other.toMap() == toMap(); } @override int get hashCode => toMap().hashCode; String toJson() => encode(toMap()); dynamic decode(String json) => jsonDecode(json); String encode(dynamic json) => jsonEncode(json); }