✨ Friend request indicator
This commit is contained in:
		@@ -85,7 +85,7 @@ class _BootstrapperShellState extends State<BootstrapperShell> {
 | 
				
			|||||||
          await Future.wait([
 | 
					          await Future.wait([
 | 
				
			||||||
            Get.find<RealmProvider>().refreshAvailableRealms(),
 | 
					            Get.find<RealmProvider>().refreshAvailableRealms(),
 | 
				
			||||||
            Get.find<ChannelProvider>().refreshAvailableChannel(),
 | 
					            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';
 | 
					import 'package:solian/providers/auth.dart';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class RelationshipProvider extends GetxController {
 | 
					class RelationshipProvider extends GetxController {
 | 
				
			||||||
 | 
					  final RxInt friendRequestCount = 0.obs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  final RxList<Relationship> _friends = RxList.empty(growable: true);
 | 
					  final RxList<Relationship> _friends = RxList.empty(growable: true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Future<void> refreshFriendList() async {
 | 
					  Future<void> refreshRelativeList() async {
 | 
				
			||||||
    final resp = await listRelationWithStatus(1);
 | 
					    final resp = await listRelation();
 | 
				
			||||||
    _friends.value = resp.body
 | 
					    final List<Relationship> result = resp.body
 | 
				
			||||||
        .map((e) => Relationship.fromJson(e))
 | 
					        .map((e) => Relationship.fromJson(e))
 | 
				
			||||||
        .toList()
 | 
					        .toList()
 | 
				
			||||||
        .cast<Relationship>();
 | 
					        .cast<Relationship>();
 | 
				
			||||||
 | 
					    _friends.value = result.where((x) => x.status == 1).toList();
 | 
				
			||||||
    _friends.refresh();
 | 
					    _friends.refresh();
 | 
				
			||||||
 | 
					    friendRequestCount.value = result.where((x) => x.status == 0).length;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool hasFriend(Account account) {
 | 
					  bool hasFriend(Account account) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,11 +3,13 @@ import 'package:get/get.dart';
 | 
				
			|||||||
import 'package:solian/models/account.dart';
 | 
					import 'package:solian/models/account.dart';
 | 
				
			||||||
import 'package:solian/providers/auth.dart';
 | 
					import 'package:solian/providers/auth.dart';
 | 
				
			||||||
import 'package:solian/providers/account_status.dart';
 | 
					import 'package:solian/providers/account_status.dart';
 | 
				
			||||||
 | 
					import 'package:solian/providers/relation.dart';
 | 
				
			||||||
import 'package:solian/router.dart';
 | 
					import 'package:solian/router.dart';
 | 
				
			||||||
import 'package:solian/screens/auth/signin.dart';
 | 
					import 'package:solian/screens/auth/signin.dart';
 | 
				
			||||||
import 'package:solian/screens/auth/signup.dart';
 | 
					import 'package:solian/screens/auth/signup.dart';
 | 
				
			||||||
import 'package:solian/widgets/account/account_heading.dart';
 | 
					import 'package:solian/widgets/account/account_heading.dart';
 | 
				
			||||||
import 'package:solian/widgets/sized_container.dart';
 | 
					import 'package:solian/widgets/sized_container.dart';
 | 
				
			||||||
 | 
					import 'package:badges/badges.dart' as badges;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AccountScreen extends StatefulWidget {
 | 
					class AccountScreen extends StatefulWidget {
 | 
				
			||||||
  const AccountScreen({super.key});
 | 
					  const AccountScreen({super.key});
 | 
				
			||||||
@@ -23,9 +25,27 @@ class _AccountScreenState extends State<AccountScreen> {
 | 
				
			|||||||
      (
 | 
					      (
 | 
				
			||||||
        const Icon(Icons.color_lens),
 | 
					        const Icon(Icons.color_lens),
 | 
				
			||||||
        'accountPersonalize'.tr,
 | 
					        '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();
 | 
					    final AuthProvider auth = Get.find();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,6 +38,9 @@ class _FriendScreenState extends State<FriendScreen>
 | 
				
			|||||||
          .cast<Relationship>();
 | 
					          .cast<Relationship>();
 | 
				
			||||||
      _isBusy = false;
 | 
					      _isBusy = false;
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    relations.friendRequestCount.value =
 | 
				
			||||||
 | 
					        _relations.where((x) => x.status == 0).length;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void promptAddFriend() async {
 | 
					  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/account_status.dart';
 | 
				
			||||||
import 'package:solian/providers/auth.dart';
 | 
					import 'package:solian/providers/auth.dart';
 | 
				
			||||||
import 'package:solian/providers/content/channel.dart';
 | 
					import 'package:solian/providers/content/channel.dart';
 | 
				
			||||||
 | 
					import 'package:solian/providers/relation.dart';
 | 
				
			||||||
import 'package:solian/router.dart';
 | 
					import 'package:solian/router.dart';
 | 
				
			||||||
import 'package:solian/shells/root_shell.dart';
 | 
					import 'package:solian/shells/root_shell.dart';
 | 
				
			||||||
import 'package:solian/theme.dart';
 | 
					import 'package:solian/theme.dart';
 | 
				
			||||||
@@ -60,8 +61,7 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
 | 
				
			|||||||
          AppRouter.instance.pushNamed('settings');
 | 
					          AppRouter.instance.pushNamed('settings');
 | 
				
			||||||
          setState(() => _selectedIndex = null);
 | 
					          setState(() => _selectedIndex = null);
 | 
				
			||||||
          _closeDrawer();
 | 
					          _closeDrawer();
 | 
				
			||||||
        }
 | 
					        });
 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
@@ -130,22 +130,36 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
 | 
				
			|||||||
                );
 | 
					                );
 | 
				
			||||||
              },
 | 
					              },
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
            leading: Builder(builder: (context) {
 | 
					            leading: Obx(() {
 | 
				
			||||||
              final badgeColor = _accountStatus != null
 | 
					              final statusBadgeColor = _accountStatus != null
 | 
				
			||||||
                  ? StatusProvider.determineStatus(
 | 
					                  ? StatusProvider.determineStatus(
 | 
				
			||||||
                      _accountStatus!,
 | 
					                      _accountStatus!,
 | 
				
			||||||
                    ).$2
 | 
					                    ).$2
 | 
				
			||||||
                  : Colors.grey;
 | 
					                  : Colors.grey;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              final RelationshipProvider relations = Get.find();
 | 
				
			||||||
 | 
					              final accountNotifications = relations.friendRequestCount.value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              return badges.Badge(
 | 
					              return badges.Badge(
 | 
				
			||||||
                showBadge: _accountStatus != null,
 | 
					                badgeContent: Text(
 | 
				
			||||||
                badgeStyle: badges.BadgeStyle(badgeColor: badgeColor),
 | 
					                  accountNotifications.toString(),
 | 
				
			||||||
                position: badges.BadgePosition.bottomEnd(
 | 
					                  style: const TextStyle(color: Colors.white),
 | 
				
			||||||
                  bottom: 0,
 | 
					 | 
				
			||||||
                  end: -2,
 | 
					 | 
				
			||||||
                ),
 | 
					                ),
 | 
				
			||||||
                child: AccountAvatar(
 | 
					                showBadge: accountNotifications > 0,
 | 
				
			||||||
                  content: auth.userProfile.value!['avatar'],
 | 
					                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'],
 | 
				
			||||||
 | 
					                  ),
 | 
				
			||||||
                ),
 | 
					                ),
 | 
				
			||||||
              );
 | 
					              );
 | 
				
			||||||
            }),
 | 
					            }),
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user