✨ Friend request indicator
This commit is contained in:
parent
425bae9d13
commit
4616f3a3e2
@ -85,7 +85,7 @@ class _BootstrapperShellState extends State<BootstrapperShell> {
|
||||
await Future.wait([
|
||||
Get.find<RealmProvider>().refreshAvailableRealms(),
|
||||
Get.find<ChannelProvider>().refreshAvailableChannel(),
|
||||
Get.find<RelationshipProvider>().refreshFriendList(),
|
||||
Get.find<RelationshipProvider>().refreshRelativeList(),
|
||||
]);
|
||||
}
|
||||
},
|
||||
|
@ -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<Relationship> _friends = RxList.empty(growable: true);
|
||||
|
||||
Future<void> refreshFriendList() async {
|
||||
final resp = await listRelationWithStatus(1);
|
||||
_friends.value = resp.body
|
||||
Future<void> refreshRelativeList() async {
|
||||
final resp = await listRelation();
|
||||
final List<Relationship> result = resp.body
|
||||
.map((e) => Relationship.fromJson(e))
|
||||
.toList()
|
||||
.cast<Relationship>();
|
||||
_friends.value = result.where((x) => x.status == 1).toList();
|
||||
_friends.refresh();
|
||||
friendRequestCount.value = result.where((x) => x.status == 0).length;
|
||||
}
|
||||
|
||||
bool hasFriend(Account account) {
|
||||
|
@ -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<AccountScreen> {
|
||||
(
|
||||
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();
|
||||
|
@ -38,6 +38,9 @@ class _FriendScreenState extends State<FriendScreen>
|
||||
.cast<Relationship>();
|
||||
_isBusy = false;
|
||||
});
|
||||
|
||||
relations.friendRequestCount.value =
|
||||
_relations.where((x) => x.status == 0).length;
|
||||
}
|
||||
|
||||
void promptAddFriend() async {
|
||||
|
@ -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<AppNavigationDrawer> {
|
||||
AppRouter.instance.pushNamed('settings');
|
||||
setState(() => _selectedIndex = null);
|
||||
_closeDrawer();
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@ -130,16 +130,29 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
|
||||
);
|
||||
},
|
||||
),
|
||||
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(
|
||||
badgeContent: Text(
|
||||
accountNotifications.toString(),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
showBadge: accountNotifications > 0,
|
||||
position: badges.BadgePosition.topEnd(
|
||||
top: -10,
|
||||
end: -6,
|
||||
),
|
||||
child: badges.Badge(
|
||||
showBadge: _accountStatus != null,
|
||||
badgeStyle: badges.BadgeStyle(badgeColor: badgeColor),
|
||||
badgeStyle: badges.BadgeStyle(badgeColor: statusBadgeColor),
|
||||
position: badges.BadgePosition.bottomEnd(
|
||||
bottom: 0,
|
||||
end: -2,
|
||||
@ -147,6 +160,7 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
|
||||
child: AccountAvatar(
|
||||
content: auth.userProfile.value!['avatar'],
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
trailing: _buildSettingButton(),
|
||||
|
Loading…
Reference in New Issue
Block a user