intro get_it_mix and implemente deleting friend
parent
9a5ecc9643
commit
16a7a83e42
|
@ -4,7 +4,7 @@ class FriendSetting {
|
|||
String friendRemark = '';
|
||||
String friendGroup = '';
|
||||
|
||||
FriendSetting.fromJson(Map<String, dynamic> json) {
|
||||
FriendSetting.fromJson(Map json) {
|
||||
friendRemark = json['friendRemark'] ?? '';
|
||||
friendGroup = json['friendGroup'] ?? '我的好友';
|
||||
}
|
||||
|
@ -36,9 +36,10 @@ class Contact extends ChangeNotifier {
|
|||
// groupChats[key] = GroupChatSetting.fromJson(value);
|
||||
// });
|
||||
|
||||
for (String i in json['friendGroups']) {
|
||||
friendGroups.add(i);
|
||||
}
|
||||
// for (String i in json['friendGroups']) {
|
||||
// friendGroups.add(i);
|
||||
// }
|
||||
friendGroups = List.from(json['friendGroups']);
|
||||
}
|
||||
|
||||
Map<String, FriendSetting> filterGroupFriends(String groupName) {
|
||||
|
@ -51,6 +52,11 @@ class Contact extends ChangeNotifier {
|
|||
return groupFriends;
|
||||
}
|
||||
|
||||
void addFriend(String friendId, Map friendSetting) {
|
||||
friends[friendId] = FriendSetting.fromJson(friendSetting);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void changeFriendRemark(String friendId, String remark) {
|
||||
friends[friendId]!.friendRemark = remark;
|
||||
}
|
||||
|
@ -59,23 +65,9 @@ class Contact extends ChangeNotifier {
|
|||
friends[friendId]!.friendGroup = group;
|
||||
}
|
||||
|
||||
void manageGroup(
|
||||
List<String> newGroups,
|
||||
List<List<String>> groupNameChangePair,
|
||||
String newDefaultGroup,
|
||||
) {
|
||||
defaultGroup = newDefaultGroup;
|
||||
friendGroups = newGroups;
|
||||
for (var pair in groupNameChangePair) {
|
||||
if (pair[1].isEmpty) {
|
||||
continue;
|
||||
}
|
||||
friends.forEach((key, value) {
|
||||
if (value.friendGroup == pair[0]) {
|
||||
friends[key]!.friendGroup = pair[1];
|
||||
}
|
||||
});
|
||||
}
|
||||
void removeFriend(String friendId) {
|
||||
friends.remove(friendId);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,4 +105,23 @@ class ContactAccountProfile extends ChangeNotifier {
|
|||
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 removeFriend(String friendId) {
|
||||
friends.remove(friendId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ Future<Map<String, dynamic>> manageGroups(
|
|||
String userId,
|
||||
List<String> groups,
|
||||
List<List<String>> groupNameChangePair,
|
||||
List<String> deletedOriginGroups,
|
||||
String defaultGroup,
|
||||
) async {
|
||||
Response response = await request.post(
|
||||
|
@ -70,9 +71,25 @@ Future<Map<String, dynamic>> manageGroups(
|
|||
'user_id': userId,
|
||||
'groups': groups,
|
||||
'group_name_change_pair': groupNameChangePair,
|
||||
'deleted_origin_groups': deletedOriginGroups,
|
||||
'default_group': defaultGroup,
|
||||
},
|
||||
);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> deleteFriend(
|
||||
String userId,
|
||||
String friendId,
|
||||
) async {
|
||||
Response response = await request.post(
|
||||
'/contact/delete/friend',
|
||||
data: {
|
||||
'user_id': userId,
|
||||
'friend_id': friendId,
|
||||
},
|
||||
);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import 'package:together_mobile/screens/message/message_screen.dart';
|
|||
final chatRouter = GoRoute(
|
||||
path: '/chat',
|
||||
name: 'Chat',
|
||||
builder: (context, state) => const ChatScreen(),
|
||||
builder: (context, state) => ChatScreen(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'message',
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:together_mobile/models/contact_model.dart';
|
||||
import 'package:together_mobile/models/init_get_it.dart';
|
||||
import 'package:together_mobile/screens/contact/contact_apply_screen/applicant_profile_screen/applicant_profile_screen.dart';
|
||||
import 'package:together_mobile/screens/friend_profile/friend_setting_screen/friend_setting_screen.dart';
|
||||
|
||||
import 'router_key.dart';
|
||||
import 'package:together_mobile/screens/contact/contact_apply_screen/apply_list_screen.dart';
|
||||
import 'package:together_mobile/screens/contact/contact_screen.dart';
|
||||
import 'package:together_mobile/screens/contact/friend_group_screen/friend_group_screen.dart';
|
||||
import 'package:together_mobile/screens/contact/manage_group_screen/manage_group_screen.dart';
|
||||
import 'package:together_mobile/screens/contact_add/contact_add_friend_screen/add_friend_screen.dart';
|
||||
import 'package:together_mobile/screens/contact_add/search_new_screen.dart';
|
||||
import 'package:together_mobile/screens/friend_profile/friend_profile_screen.dart';
|
||||
|
@ -16,7 +18,14 @@ import 'package:together_mobile/screens/group_chat_profile/group_chat_profile_sc
|
|||
final contactRouter = GoRoute(
|
||||
path: '/contact',
|
||||
name: 'Contact',
|
||||
builder: (context, state) => const ContactScreen(),
|
||||
builder: (context, state) {
|
||||
if (state.queryParameters.isNotEmpty) {
|
||||
var deletedFriendId = state.queryParameters['deletedFriendId'];
|
||||
getIt.get<Contact>().removeFriend(deletedFriendId!);
|
||||
getIt.get<ContactAccountProfile>().removeFriend(deletedFriendId);
|
||||
}
|
||||
return ContactScreen();
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'add',
|
||||
|
@ -92,7 +101,9 @@ final contactRouter = GoRoute(
|
|||
path: 'friend_setting',
|
||||
name: 'FriendSetting',
|
||||
parentNavigatorKey: rootNavigatorKey,
|
||||
builder: (context, state) => FriendSettingScreen(friendId: state.queryParameters['friendId']!,),
|
||||
builder: (context, state) => FriendSettingScreen(
|
||||
friendId: state.queryParameters['friendId']!,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:together_mobile/models/contact_model.dart';
|
||||
|
||||
import 'components/chat_tile.dart';
|
||||
import 'package:together_mobile/models/contact_model.dart';
|
||||
import 'package:together_mobile/models/apply_list_model.dart';
|
||||
import 'package:together_mobile/request/apply.dart';
|
||||
import 'package:together_mobile/request/server.dart';
|
||||
|
|
|
@ -18,29 +18,30 @@ class FriendGroup extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _FriendGroupState extends State<FriendGroup> {
|
||||
late Map<String, FriendSetting> _groupFriends;
|
||||
late List<FriendTile> _friendTiles;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_groupFriends = getIt.get<Contact>().filterGroupFriends(widget.groupName);
|
||||
_friendTiles = List.generate(
|
||||
_groupFriends.length,
|
||||
(index) => FriendTile(
|
||||
key: ValueKey(
|
||||
getIt.get<Contact>().friends.keys.toList()[index],
|
||||
),
|
||||
friendId: _groupFriends.keys.toList()[index]),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ExpansionTile(
|
||||
title: Text(widget.groupName),
|
||||
trailing: Text(_friendTiles.length.toString()),
|
||||
children: _friendTiles,
|
||||
trailing: Text(
|
||||
getIt
|
||||
.get<Contact>()
|
||||
.filterGroupFriends(widget.groupName)
|
||||
.length
|
||||
.toString(),
|
||||
),
|
||||
children: List.generate(
|
||||
getIt.get<Contact>().filterGroupFriends(widget.groupName).length,
|
||||
(index) => FriendTile(
|
||||
key: ValueKey(
|
||||
getIt.get<Contact>().friends.keys.toList()[index],
|
||||
),
|
||||
friendId: getIt
|
||||
.get<Contact>()
|
||||
.filterGroupFriends(widget.groupName)
|
||||
.keys
|
||||
.toList()[index],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -6,8 +5,6 @@ import 'package:flutter/material.dart';
|
|||
import 'package:together_mobile/common/constants.dart';
|
||||
import 'package:together_mobile/request/server.dart';
|
||||
import 'package:together_mobile/screens/friend_profile/components/friend_profile_card.dart';
|
||||
import 'package:together_mobile/models/init_get_it.dart';
|
||||
import 'package:together_mobile/models/user_model.dart';
|
||||
|
||||
class ApplicantProfileScreen extends StatelessWidget {
|
||||
const ApplicantProfileScreen({
|
||||
|
|
|
@ -7,13 +7,12 @@ import 'package:go_router/go_router.dart';
|
|||
|
||||
import 'package:together_mobile/common/constants.dart';
|
||||
import 'package:together_mobile/models/apply_list_model.dart';
|
||||
import 'package:together_mobile/models/contact_model.dart';
|
||||
import 'package:together_mobile/models/init_get_it.dart';
|
||||
import 'package:together_mobile/models/user_model.dart';
|
||||
import 'package:together_mobile/request/apply.dart';
|
||||
import 'package:together_mobile/request/server.dart';
|
||||
|
||||
const List<String> friendGroup = ['我的好友', '同学', '同事', '朋友', '家人'];
|
||||
|
||||
class ApplyBottomSheet extends StatefulWidget {
|
||||
const ApplyBottomSheet({
|
||||
super.key,
|
||||
|
@ -33,7 +32,7 @@ class ApplyBottomSheet extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _ApplyBottomSheetState extends State<ApplyBottomSheet> {
|
||||
String _curValue = friendGroup.first;
|
||||
String _curValue = getIt.get<Contact>().friendGroups.first;
|
||||
final _remarkController = TextEditingController();
|
||||
|
||||
@override
|
||||
|
@ -163,7 +162,10 @@ class _ApplyBottomSheetState extends State<ApplyBottomSheet> {
|
|||
_curValue = value!;
|
||||
});
|
||||
},
|
||||
items: friendGroup.map<DropdownMenuItem<String>>((String value) {
|
||||
items: getIt
|
||||
.get<Contact>()
|
||||
.friendGroups
|
||||
.map<DropdownMenuItem<String>>((String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value),
|
||||
|
@ -212,12 +214,24 @@ class _ApplyBottomSheetState extends State<ApplyBottomSheet> {
|
|||
|
||||
if (res['code'] == 10600) {
|
||||
// ignore: use_build_context_synchronously
|
||||
CherryToast.success(title: const Text('添加好友成功')).show(context);
|
||||
CherryToast.success(
|
||||
title: const Text(
|
||||
'添加好友成功',
|
||||
style: TextStyle(
|
||||
color: kContentColorLight,
|
||||
),
|
||||
)).show(context);
|
||||
getIt.get<ApplyList>().removeAt(widget.index);
|
||||
widget.refreshCallback();
|
||||
getIt.get<Contact>().addFriend(widget.apply.applicant!, recipientSetting);
|
||||
} else {
|
||||
// ignore: use_build_context_synchronously
|
||||
CherryToast.error(title: const Text('添加失败,稍后重试')).show(context);
|
||||
CherryToast.error(
|
||||
title: const Text(
|
||||
'添加失败,稍后重试',
|
||||
style: TextStyle(color: kContentColorLight),
|
||||
),
|
||||
).show(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:badges/badges.dart' as badges;
|
||||
import 'package:visibility_detector/visibility_detector.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:get_it_mixin/get_it_mixin.dart';
|
||||
|
||||
import 'package:together_mobile/common/constants.dart';
|
||||
import 'package:together_mobile/models/apply_list_model.dart';
|
||||
import 'package:together_mobile/models/contact_model.dart';
|
||||
import 'package:together_mobile/models/init_get_it.dart';
|
||||
import 'package:together_mobile/models/user_model.dart';
|
||||
import 'package:together_mobile/request/server.dart';
|
||||
import 'package:together_mobile/screens/contact/components/friend_group.dart';
|
||||
import 'package:together_mobile/screens/contact/components/friend_tile.dart';
|
||||
import 'package:together_mobile/screens/contact/components/group_chat_tile.dart';
|
||||
|
||||
class ContactScreen extends StatefulWidget {
|
||||
const ContactScreen({super.key});
|
||||
class ContactScreen extends StatefulWidget with GetItStatefulWidgetMixin {
|
||||
ContactScreen({super.key});
|
||||
|
||||
@override
|
||||
State<ContactScreen> createState() => _ContactScreenState();
|
||||
}
|
||||
|
||||
class _ContactScreenState extends State<ContactScreen> {
|
||||
class _ContactScreenState extends State<ContactScreen> with GetItStateMixin {
|
||||
final Map<String, bool> _shows = {
|
||||
'friendGroups': true,
|
||||
'allFriends': false,
|
||||
|
@ -30,6 +30,13 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Map<String, FriendSetting> friends = watchOnly(
|
||||
(Contact contact) => contact.friends,
|
||||
);
|
||||
List<String> friendGroups = watchOnly(
|
||||
(Contact contact) => contact.friendGroups,
|
||||
);
|
||||
|
||||
// Create a localkey, use to generate the custom scroll view,
|
||||
// or there will be a error: "Duplicate GlobalKey detected in widget tree."
|
||||
// But when I wrap custom scroll view into the RefrashIndicator, the key isn't needed any more
|
||||
|
@ -39,13 +46,13 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||
appBar: AppBar(
|
||||
leading: Container(
|
||||
margin: const EdgeInsets.only(left: 8),
|
||||
child: getIt.get<UserProfile>().avatar.isEmpty
|
||||
child: get<UserProfile>().avatar.isEmpty
|
||||
? const CircleAvatar(
|
||||
backgroundImage: AssetImage('assets/images/user_2.png'),
|
||||
)
|
||||
: CircleAvatar(
|
||||
backgroundImage: CachedNetworkImageProvider(
|
||||
'$avatarsUrl/${getIt.get<UserProfile>().avatar}',
|
||||
'$avatarsUrl/${get<UserProfile>().avatar}',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -79,7 +86,7 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||
[
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
// await getApplicantInfo(getIt.get<ApplyList>().applicantIds);
|
||||
// await getApplicantInfo(get<ApplyList>().applicantIds);
|
||||
context.push('/contact/apply_list');
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
|
@ -89,13 +96,13 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
badges.Badge(
|
||||
showBadge: getIt.get<ApplyList>().count > 0,
|
||||
showBadge: get<ApplyList>().count > 0,
|
||||
badgeStyle: const badges.BadgeStyle(
|
||||
badgeColor: kErrorColor,
|
||||
elevation: 12,
|
||||
),
|
||||
badgeContent: Text(
|
||||
getIt.get<ApplyList>().count.toString(),
|
||||
get<ApplyList>().count.toString(),
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color:
|
||||
|
@ -158,26 +165,25 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||
(BuildContext context, int index) {
|
||||
if (_shows['friendGroups']!) {
|
||||
return FriendGroup(
|
||||
key: ValueKey(getIt.get<Contact>().friendGroups[index]),
|
||||
groupName: getIt.get<Contact>().friendGroups[index],
|
||||
key: ValueKey(friendGroups[index]),
|
||||
groupName: friendGroups[index],
|
||||
);
|
||||
} else if (_shows['allFriends']!) {
|
||||
return FriendTile(
|
||||
key: ValueKey(
|
||||
getIt.get<Contact>().friends.keys.toList()[index],
|
||||
friends.keys.toList()[index],
|
||||
),
|
||||
friendId:
|
||||
getIt.get<Contact>().friends.keys.toList()[index],
|
||||
friendId: friends.keys.toList()[index],
|
||||
);
|
||||
} else {
|
||||
return GroupChatTile();
|
||||
}
|
||||
},
|
||||
childCount: _shows['friendGroups']!
|
||||
? getIt.get<Contact>().friendGroups.length
|
||||
? get<Contact>().friendGroups.length
|
||||
: _shows['allFriends']!
|
||||
? getIt.get<Contact>().friends.length
|
||||
: getIt.get<Contact>().groupChats.length,
|
||||
? get<Contact>().friends.length
|
||||
: get<Contact>().groupChats.length,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -4,6 +4,8 @@ import 'package:go_router/go_router.dart';
|
|||
import 'package:cherry_toast/cherry_toast.dart';
|
||||
|
||||
import 'package:together_mobile/common/constants.dart';
|
||||
import 'package:together_mobile/models/contact_model.dart';
|
||||
import 'package:together_mobile/models/init_get_it.dart';
|
||||
|
||||
class EditGroupBottomSheet extends StatefulWidget {
|
||||
const EditGroupBottomSheet({
|
||||
|
@ -130,18 +132,48 @@ class _EditGroupBottomSheetState extends State<EditGroupBottomSheet> {
|
|||
thickness: 1,
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (widget.tempGroups[widget.index] == widget.tempDefaultGroup) {
|
||||
onPressed: () async {
|
||||
String deletedGroup = widget.tempGroups[widget.index];
|
||||
if (deletedGroup == widget.tempDefaultGroup) {
|
||||
CherryToast.warning(
|
||||
title: const Text('不可删除默认分组'),
|
||||
title: const Text(
|
||||
'不可删除默认分组',
|
||||
style: TextStyle(
|
||||
color: kContentColorLight,
|
||||
),
|
||||
),
|
||||
).show(context);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int? choose = await showDialog<int>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('删除分组'),
|
||||
content: const Text('该分组内的好友将被移到默认分组'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop<int>(0),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => context.pop<int>(1),
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (choose == 1) {
|
||||
// close the bottomsheet
|
||||
// ignore: use_build_context_synchronously
|
||||
context.pop();
|
||||
widget.deleteCallback(widget.index);
|
||||
widget.refreshCallback();
|
||||
}
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
fixedSize: const Size(240, 40),
|
|
@ -5,7 +5,7 @@ import 'package:flutter_slidable/flutter_slidable.dart';
|
|||
|
||||
import 'package:reorderables/reorderables.dart';
|
||||
import 'package:together_mobile/common/constants.dart';
|
||||
import 'package:together_mobile/screens/contact/friend_group_screen/components/group_bottom_sheet.dart';
|
||||
import 'package:together_mobile/screens/contact/manage_group_screen/components/group_bottom_sheet.dart';
|
||||
|
||||
class ReorderableFriendGroupList extends StatefulWidget {
|
||||
const ReorderableFriendGroupList({
|
||||
|
@ -62,7 +62,9 @@ class _ReorderableFriendGroupListState
|
|||
onPressed: (BuildContext context) {
|
||||
if (widget.tempGroups[index] == widget.tempDefaultGroup) {
|
||||
CherryToast.warning(
|
||||
title: const Text('不可删除默认分组'),
|
||||
title: const Text(
|
||||
'不可删除默认分组',
|
||||
),
|
||||
).show(context);
|
||||
return;
|
||||
}
|
|
@ -9,7 +9,7 @@ import 'package:together_mobile/models/init_get_it.dart';
|
|||
import 'package:together_mobile/models/user_model.dart';
|
||||
import 'package:together_mobile/request/contact.dart';
|
||||
|
||||
import 'package:together_mobile/screens/contact/friend_group_screen/components/reorderable_friend_group_list.dart';
|
||||
import 'package:together_mobile/screens/contact/manage_group_screen/components/reorderable_friend_group_list.dart';
|
||||
|
||||
class FriendGroupScreen extends StatefulWidget {
|
||||
const FriendGroupScreen({super.key});
|
||||
|
@ -22,6 +22,7 @@ class _FriendGroupScreenState extends State<FriendGroupScreen> {
|
|||
bool _isChanged = false;
|
||||
final List<String> _tempGroups = [];
|
||||
final List<List<String>> _groupNameChangePair = [];
|
||||
final List<String> _deletedOriginGroups = [];
|
||||
String _tempDefaultGroup = getIt.get<Contact>().defaultGroup;
|
||||
|
||||
@override
|
||||
|
@ -59,7 +60,7 @@ class _FriendGroupScreenState extends State<FriendGroupScreen> {
|
|||
? kUnActivatedColor
|
||||
: Theme.of(context).brightness == Brightness.light
|
||||
? kContentColorDark
|
||||
: kContentColorLight,
|
||||
: kPrimaryColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -85,6 +86,12 @@ class _FriendGroupScreenState extends State<FriendGroupScreen> {
|
|||
}
|
||||
|
||||
void _delete(int index) {
|
||||
if (getIt.get<Contact>().friendGroups.contains(_tempGroups[index])) {
|
||||
setState(() {
|
||||
_deletedOriginGroups.add(_tempGroups[index]);
|
||||
});
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_tempGroups.removeAt(index);
|
||||
_isChanged = !listEquals(_tempGroups, getIt.get<Contact>().friendGroups);
|
||||
|
@ -118,25 +125,32 @@ class _FriendGroupScreenState extends State<FriendGroupScreen> {
|
|||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
int sub =
|
||||
getIt.get<Contact>().friendGroups.length - _deletedOriginGroups.length;
|
||||
|
||||
setState(() {
|
||||
_deletedOriginGroups.addAll(List.filled(sub - 1, ''));
|
||||
});
|
||||
|
||||
Map<String, dynamic> res = await manageGroups(
|
||||
getIt.get<UserAccount>().id,
|
||||
_tempGroups,
|
||||
_groupNameChangePair,
|
||||
_deletedOriginGroups,
|
||||
_tempDefaultGroup,
|
||||
);
|
||||
|
||||
if (res['code'] == 10700) {
|
||||
// ignore: use_build_context_synchronously
|
||||
CherryToast.success(
|
||||
title: const Text('保存更改成功'),
|
||||
title: const Text(
|
||||
'保存更改成功',
|
||||
style: TextStyle(color: kContentColorLight),
|
||||
),
|
||||
).show(context);
|
||||
}
|
||||
|
||||
getIt.get<Contact>().manageGroup(
|
||||
_tempGroups,
|
||||
_groupNameChangePair,
|
||||
_tempDefaultGroup,
|
||||
);
|
||||
getIt.get<Contact>().init(res['data']);
|
||||
|
||||
setState(() {
|
||||
_isChanged = false;
|
|
@ -1,15 +1,16 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:cherry_toast/cherry_toast.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:cherry_toast/cherry_toast.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'package:together_mobile/common/constants.dart';
|
||||
import 'package:together_mobile/models/contact_model.dart';
|
||||
import 'package:together_mobile/models/init_get_it.dart';
|
||||
import 'package:together_mobile/models/user_model.dart';
|
||||
import 'package:together_mobile/request/apply.dart';
|
||||
|
||||
const List<String> friendGroup = ['我的好友', '同学', '同事', '朋友', '家人'];
|
||||
import 'package:together_mobile/request/server.dart';
|
||||
|
||||
class AddBottomSheet extends StatefulWidget {
|
||||
const AddBottomSheet({super.key, required this.friendId});
|
||||
|
@ -23,7 +24,7 @@ class AddBottomSheet extends StatefulWidget {
|
|||
class _AddBottomSheetState extends State<AddBottomSheet> {
|
||||
final TextEditingController _helloController = TextEditingController();
|
||||
final TextEditingController _remarkController = TextEditingController();
|
||||
String _selectedGroup = friendGroup.first;
|
||||
String _selectedGroup = getIt.get<Contact>().friendGroups.first;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
|
@ -62,8 +63,8 @@ class _AddBottomSheetState extends State<AddBottomSheet> {
|
|||
)
|
||||
: CircleAvatar(
|
||||
radius: 30,
|
||||
backgroundImage: FileImage(
|
||||
File(getIt.get<UserProfile>().avatar),
|
||||
backgroundImage: CachedNetworkImageProvider(
|
||||
'$avatarsUrl/${getIt.get<UserProfile>().avatar}',
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
|
@ -149,7 +150,10 @@ class _AddBottomSheetState extends State<AddBottomSheet> {
|
|||
_selectedGroup = value!;
|
||||
});
|
||||
},
|
||||
items: friendGroup.map<DropdownMenuItem<String>>((String value) {
|
||||
items: getIt
|
||||
.get<Contact>()
|
||||
.friendGroups
|
||||
.map<DropdownMenuItem<String>>((String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value),
|
||||
|
@ -206,7 +210,14 @@ class _AddBottomSheetState extends State<AddBottomSheet> {
|
|||
context.pop();
|
||||
|
||||
// ignore: use_build_context_synchronously
|
||||
CherryToast.success(title: const Text('已发送添加申请')).show(context);
|
||||
CherryToast.success(
|
||||
title: const Text(
|
||||
'已发送添加申请',
|
||||
style: TextStyle(
|
||||
color: kContentColorLight,
|
||||
),
|
||||
),
|
||||
).show(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'package:together_mobile/common/constants.dart';
|
||||
import 'package:together_mobile/models/contact_model.dart';
|
||||
import 'package:together_mobile/models/init_get_it.dart';
|
||||
import 'package:together_mobile/models/user_model.dart';
|
||||
import 'package:together_mobile/request/search_new.dart';
|
||||
|
@ -127,19 +128,33 @@ class _SearchNewScreenState extends State<SearchNewScreen> {
|
|||
return;
|
||||
}
|
||||
|
||||
if (_controller.text == getIt.get<UserAccount>().username ||
|
||||
_controller.text == getIt.get<UserAccount>().email) {
|
||||
String searchValue = _controller.text;
|
||||
|
||||
if (searchValue == getIt.get<UserAccount>().username ||
|
||||
searchValue == getIt.get<UserAccount>().email) {
|
||||
context.pushNamed('MainProfile');
|
||||
return;
|
||||
}
|
||||
|
||||
var (isExisted, friendId) = getIt.get<ContactAccountProfile>().getIdBy(
|
||||
'username',
|
||||
searchValue,
|
||||
);
|
||||
if (isExisted) {
|
||||
context.pushNamed(
|
||||
'FriendProfile',
|
||||
queryParameters: {'friendId': friendId},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isHttpSent = true;
|
||||
});
|
||||
|
||||
Map<String, dynamic> res = await searchContactBy(
|
||||
condition,
|
||||
_controller.text,
|
||||
searchValue,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:cherry_toast/cherry_toast.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'package:together_mobile/common/constants.dart';
|
||||
import 'package:together_mobile/models/init_get_it.dart';
|
||||
import 'package:together_mobile/models/contact_model.dart';
|
||||
import 'package:together_mobile/models/user_model.dart';
|
||||
import 'package:together_mobile/request/contact.dart';
|
||||
|
||||
class FriendSettingScreen extends StatefulWidget {
|
||||
|
@ -48,7 +52,9 @@ class _FriendSettingScreenState extends State<FriendSettingScreen> {
|
|||
centerTitle: true,
|
||||
title: const Text('好友设置'),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: ExpansionPanelList(
|
||||
expansionCallback: (panelIndex, isExpanded) {
|
||||
setState(() {
|
||||
|
@ -151,7 +157,8 @@ class _FriendSettingScreenState extends State<FriendSettingScreen> {
|
|||
backgroundColor: _isRemarkChanged &&
|
||||
_remarkController.text.isNotEmpty
|
||||
? kPrimaryColor
|
||||
: Theme.of(context).brightness == Brightness.dark
|
||||
: Theme.of(context).brightness ==
|
||||
Brightness.dark
|
||||
? kUnActivatedColor
|
||||
: kUnAvailableColor,
|
||||
),
|
||||
|
@ -238,17 +245,23 @@ class _FriendSettingScreenState extends State<FriendSettingScreen> {
|
|||
if (res['code'] == 10700) {
|
||||
// ignore: use_build_context_synchronously
|
||||
CherryToast.success(
|
||||
title: const Text('已更改好友分组'),
|
||||
title: const Text(
|
||||
'已更改好友分组',
|
||||
style: TextStyle(
|
||||
color: kContentColorLight,
|
||||
),
|
||||
),
|
||||
).show(context);
|
||||
|
||||
setState(() {
|
||||
_isGroupChanged = false;
|
||||
});
|
||||
|
||||
getIt.get<Contact>().changeFriendGroup(
|
||||
widget.friendId,
|
||||
_group,
|
||||
);
|
||||
// getIt.get<Contact>().changeFriendGroup(
|
||||
// widget.friendId,
|
||||
// _group,
|
||||
// );
|
||||
getIt.get<Contact>().init(res['data']);
|
||||
}
|
||||
},
|
||||
style: FilledButton.styleFrom(
|
||||
|
@ -259,7 +272,8 @@ class _FriendSettingScreenState extends State<FriendSettingScreen> {
|
|||
),
|
||||
backgroundColor: _isGroupChanged
|
||||
? kPrimaryColor
|
||||
: Theme.of(context).brightness == Brightness.dark
|
||||
: Theme.of(context).brightness ==
|
||||
Brightness.dark
|
||||
? kUnActivatedColor
|
||||
: kUnAvailableColor,
|
||||
),
|
||||
|
@ -276,6 +290,81 @@ class _FriendSettingScreenState extends State<FriendSettingScreen> {
|
|||
],
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: TextButton(
|
||||
onPressed: () async {
|
||||
await _deleteFriend(context);
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: kErrorColor.withOpacity(0.4),
|
||||
),
|
||||
child: const Text(
|
||||
'删除好友',
|
||||
style: TextStyle(
|
||||
color: kErrorColor,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _deleteFriend(BuildContext context) async {
|
||||
int? choose = await showDialog<int>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('删除好友'),
|
||||
content: const Text('删除好友后,你将会从对方好友列表中移除'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(0),
|
||||
child: const Text(
|
||||
'取消',
|
||||
style: TextStyle(
|
||||
color: kUnAvailableColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => context.pop(1),
|
||||
child: const Text(
|
||||
'确认',
|
||||
style: TextStyle(
|
||||
color: kErrorColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (choose == 1) {
|
||||
Map<String, dynamic> res = await deleteFriend(
|
||||
getIt.get<UserAccount>().id,
|
||||
widget.friendId,
|
||||
);
|
||||
|
||||
if (res['code'] == 10700) {
|
||||
// ignore: use_build_context_synchronously
|
||||
context.goNamed(
|
||||
'Contact',
|
||||
queryParameters: {'deletedFriendId': widget.friendId},
|
||||
);
|
||||
// ignore: use_build_context_synchronously
|
||||
CherryToast.success(
|
||||
title: const Text(
|
||||
'已删除好友',
|
||||
style: TextStyle(
|
||||
color: kContentColorLight,
|
||||
),
|
||||
),
|
||||
).show(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
358
pubspec.lock
358
pubspec.lock
File diff suppressed because it is too large
Load Diff
|
@ -42,6 +42,7 @@ dependencies:
|
|||
flutter_slidable: ^3.0.0
|
||||
flutter_timezone: ^1.0.6
|
||||
get_it: ^7.6.0
|
||||
get_it_mixin: ^4.2.0
|
||||
go_router: ^7.1.1
|
||||
google_fonts: ^4.0.0
|
||||
hive: ^2.2.3
|
||||
|
@ -55,7 +56,6 @@ dependencies:
|
|||
shared_preferences: ^2.2.0
|
||||
timezone: ^0.9.2
|
||||
video_player: ^2.6.1
|
||||
visibility_detector: ^0.4.0+2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_lints: ^2.0.0
|
||||
|
|
Loading…
Reference in New Issue