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