diff --git a/lib/bootstrapper.dart b/lib/bootstrapper.dart index 13950bb..53a21f4 100644 --- a/lib/bootstrapper.dart +++ b/lib/bootstrapper.dart @@ -85,7 +85,7 @@ class _BootstrapperShellState extends State { await Future.wait([ Get.find().refreshAvailableRealms(), Get.find().refreshAvailableChannel(), - Get.find().refreshFriendList(), + Get.find().refreshRelativeList(), ]); } }, diff --git a/lib/providers/relation.dart b/lib/providers/relation.dart index b4748e5..d58f2fa 100644 --- a/lib/providers/relation.dart +++ b/lib/providers/relation.dart @@ -4,15 +4,19 @@ import 'package:solian/models/relations.dart'; import 'package:solian/providers/auth.dart'; class RelationshipProvider extends GetxController { + final RxInt friendRequestCount = 0.obs; + final RxList _friends = RxList.empty(growable: true); - Future refreshFriendList() async { - final resp = await listRelationWithStatus(1); - _friends.value = resp.body + Future refreshRelativeList() async { + final resp = await listRelation(); + final List result = resp.body .map((e) => Relationship.fromJson(e)) .toList() .cast(); + _friends.value = result.where((x) => x.status == 1).toList(); _friends.refresh(); + friendRequestCount.value = result.where((x) => x.status == 0).length; } bool hasFriend(Account account) { diff --git a/lib/screens/account.dart b/lib/screens/account.dart index a7fb76c..31df715 100644 --- a/lib/screens/account.dart +++ b/lib/screens/account.dart @@ -3,11 +3,13 @@ import 'package:get/get.dart'; import 'package:solian/models/account.dart'; import 'package:solian/providers/auth.dart'; import 'package:solian/providers/account_status.dart'; +import 'package:solian/providers/relation.dart'; import 'package:solian/router.dart'; import 'package:solian/screens/auth/signin.dart'; import 'package:solian/screens/auth/signup.dart'; import 'package:solian/widgets/account/account_heading.dart'; import 'package:solian/widgets/sized_container.dart'; +import 'package:badges/badges.dart' as badges; class AccountScreen extends StatefulWidget { const AccountScreen({super.key}); @@ -23,9 +25,27 @@ class _AccountScreenState extends State { ( const Icon(Icons.color_lens), 'accountPersonalize'.tr, - 'accountPersonalize' + 'accountPersonalize', + ), + ( + Obx(() { + final RelationshipProvider relations = Get.find(); + return badges.Badge( + badgeContent: Text( + relations.friendRequestCount.value.toString(), + style: const TextStyle(color: Colors.white), + ), + showBadge: relations.friendRequestCount.value > 0, + position: badges.BadgePosition.topEnd( + top: -12, + end: -8, + ), + child: const Icon(Icons.diversity_1), + ); + }), + 'accountFriend'.tr, + 'accountFriend', ), - (const Icon(Icons.diversity_1), 'accountFriend'.tr, 'accountFriend'), ]; final AuthProvider auth = Get.find(); diff --git a/lib/screens/account/friend.dart b/lib/screens/account/friend.dart index 4fca818..3e78e8b 100644 --- a/lib/screens/account/friend.dart +++ b/lib/screens/account/friend.dart @@ -38,6 +38,9 @@ class _FriendScreenState extends State .cast(); _isBusy = false; }); + + relations.friendRequestCount.value = + _relations.where((x) => x.status == 0).length; } void promptAddFriend() async { diff --git a/lib/widgets/navigation/app_navigation_drawer.dart b/lib/widgets/navigation/app_navigation_drawer.dart index fe9e697..d8dc1bb 100644 --- a/lib/widgets/navigation/app_navigation_drawer.dart +++ b/lib/widgets/navigation/app_navigation_drawer.dart @@ -4,6 +4,7 @@ import 'package:solian/models/account_status.dart'; import 'package:solian/providers/account_status.dart'; import 'package:solian/providers/auth.dart'; import 'package:solian/providers/content/channel.dart'; +import 'package:solian/providers/relation.dart'; import 'package:solian/router.dart'; import 'package:solian/shells/root_shell.dart'; import 'package:solian/theme.dart'; @@ -60,8 +61,7 @@ class _AppNavigationDrawerState extends State { AppRouter.instance.pushNamed('settings'); setState(() => _selectedIndex = null); _closeDrawer(); - } - ); + }); } @override @@ -130,22 +130,36 @@ class _AppNavigationDrawerState extends State { ); }, ), - leading: Builder(builder: (context) { - final badgeColor = _accountStatus != null + leading: Obx(() { + final statusBadgeColor = _accountStatus != null ? StatusProvider.determineStatus( _accountStatus!, ).$2 : Colors.grey; + final RelationshipProvider relations = Get.find(); + final accountNotifications = relations.friendRequestCount.value; + return badges.Badge( - showBadge: _accountStatus != null, - badgeStyle: badges.BadgeStyle(badgeColor: badgeColor), - position: badges.BadgePosition.bottomEnd( - bottom: 0, - end: -2, + badgeContent: Text( + accountNotifications.toString(), + style: const TextStyle(color: Colors.white), ), - child: AccountAvatar( - content: auth.userProfile.value!['avatar'], + showBadge: accountNotifications > 0, + position: badges.BadgePosition.topEnd( + top: -10, + end: -6, + ), + child: badges.Badge( + showBadge: _accountStatus != null, + badgeStyle: badges.BadgeStyle(badgeColor: statusBadgeColor), + position: badges.BadgePosition.bottomEnd( + bottom: 0, + end: -2, + ), + child: AccountAvatar( + content: auth.userProfile.value!['avatar'], + ), ), ); }),