139 lines
3.5 KiB
Dart
139 lines
3.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class FriendSetting {
|
|
String friendRemark = '';
|
|
String friendGroup = '';
|
|
|
|
FriendSetting.fromJson(Map json) {
|
|
friendRemark = json['friendRemark'] ?? '';
|
|
friendGroup = json['friendGroup'] ?? '我的好友';
|
|
}
|
|
}
|
|
|
|
class GroupChatSetting {
|
|
String groupChatRemark = '';
|
|
String myRemark = '';
|
|
|
|
GroupChatSetting.fromJson(Map<String, dynamic> json) {
|
|
groupChatRemark = json['groupChatRemark'] ?? '';
|
|
myRemark = json['myRemark'] ?? '';
|
|
}
|
|
}
|
|
|
|
class Contact extends ChangeNotifier {
|
|
Map<String, FriendSetting> friends = {};
|
|
List<String> friendGroups = [];
|
|
String defaultGroup = '';
|
|
Map<String, GroupChatSetting> groupChats = {};
|
|
int friendCount = 0;
|
|
|
|
void init(Map json) {
|
|
defaultGroup = json['defaultGroup'];
|
|
friendCount = 0;
|
|
|
|
json['friends'].forEach((key, value) {
|
|
friendCount += 1;
|
|
friends[key] = FriendSetting.fromJson(value);
|
|
});
|
|
// json['groupChats'].forEach((key, value) {
|
|
// groupChats[key] = GroupChatSetting.fromJson(value);
|
|
// });
|
|
|
|
// for (String i in json['friendGroups']) {
|
|
// friendGroups.add(i);
|
|
// }
|
|
friendGroups = List.from(json['friendGroups']);
|
|
}
|
|
|
|
Map<String, FriendSetting> filterGroupFriends(String groupName) {
|
|
Map<String, FriendSetting> groupFriends = {};
|
|
friends.forEach((key, value) {
|
|
if (value.friendGroup == groupName) {
|
|
groupFriends[key] = value;
|
|
}
|
|
});
|
|
return groupFriends;
|
|
}
|
|
|
|
void addFriend(String friendId, Map friendSetting) {
|
|
friends[friendId] = FriendSetting.fromJson(friendSetting);
|
|
friendCount += 1;
|
|
notifyListeners();
|
|
}
|
|
|
|
void changeFriendRemark(String friendId, String remark) {
|
|
friends[friendId]!.friendRemark = remark;
|
|
}
|
|
|
|
void changeFriendGroup(String friendId, String group) {
|
|
friends[friendId]!.friendGroup = group;
|
|
}
|
|
|
|
void removeFriend(String friendId) {
|
|
friends.remove(friendId);
|
|
friendCount -= 1;
|
|
notifyListeners();
|
|
}
|
|
}
|
|
|
|
class FriendAccountProfile {
|
|
String id = '';
|
|
String username = '';
|
|
String email = '';
|
|
String nickname = '';
|
|
String gender = '';
|
|
String birthday = '';
|
|
String location = '';
|
|
String status = '';
|
|
String sign = '';
|
|
String avatar = '';
|
|
String baseAvatarPath = '';
|
|
|
|
FriendAccountProfile.fromJson(Map<String, dynamic> json) {
|
|
id = json['id'];
|
|
username = json['username'];
|
|
email = json['email'];
|
|
nickname = json['nickname'] ?? '';
|
|
birthday = json['birthday'] ?? '';
|
|
location = json['location'] ?? '';
|
|
status = json['status'] ?? '';
|
|
sign = json['sign'] ?? '';
|
|
avatar = json['avatar'] ?? '';
|
|
}
|
|
}
|
|
|
|
class ContactAccountProfile extends ChangeNotifier {
|
|
Map<String, FriendAccountProfile> friends = {};
|
|
|
|
void init(Map json) {
|
|
json['friends'].forEach((key, value) {
|
|
friends[key] = FriendAccountProfile.fromJson(value);
|
|
});
|
|
}
|
|
|
|
(bool, String) getIdBy(String condition, String filterValue) {
|
|
String friendId = '';
|
|
switch (condition) {
|
|
case 'username':
|
|
for (var key in friends.keys) {
|
|
if (friends[key]!.username == filterValue) {
|
|
friendId = key;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
return friendId.isNotEmpty ? (true, friendId) : (false, '');
|
|
}
|
|
|
|
void addAccountProfile(String friendId, Map<String, dynamic> json) {
|
|
friends.addAll({friendId: FriendAccountProfile.fromJson(json)});
|
|
notifyListeners();
|
|
}
|
|
|
|
void removeFriend(String friendId) {
|
|
friends.remove(friendId);
|
|
notifyListeners();
|
|
}
|
|
}
|