import 'dart:convert'; class Contact { final String? name; final String? subtitle; final String? photo; final bool? isGroup; Contact({ required this.name, required this.subtitle, this.photo = '', this.isGroup = false, }); factory Contact.fromJson(Map json) { return Contact( name: json['name'], subtitle: json['subtitle'], photo: json['photo'], isGroup: json['isGroup'], ); } static Map toJson(Contact contact) { return { 'name': contact.name, 'subtitle': contact.subtitle, 'photo': contact.photo, 'isGroup': false, }; } static String encode(List contacts) => json.encode( contacts .map>((contact) => Contact.toJson(contact)) .toList(), ); static List decode(String contacts) => (json.decode(contacts) as List) .map((item) => Contact.fromJson(item)) .toList(); }