I am calling addFriendsInCommunity
method to invite members into a private community but the membercount is not updated, can you share an example on how to update members in a private community? Instead of other users having to manually join? Like you have mentioned I have used StreamBuilder like below to see changes, but the member count is not being updated.
Future<AmityCommunity> addFriendsInCommunity({
required String communityId,
required List<String> userIds,
}) async {
try {
final community = await AmitySocialClient.newCommunityRepository()
.updateCommunity(communityId)
.userIds(userIds)
.update();
AppLogger.logInfo("Friends Added in Community: ${community.communityId}");
return community;
} catch (exception) {
AppLogger.logError("Friend Added in Community error = $exception");
rethrow;
}
}
Scaffold(
appBar: AppBar(
scrolledUnderElevation: 0,
leading: BackButton(
onPressed: () {
Get.back(result: true);
},
),
title: Text(widget.community.displayName ?? "N/A"),
backgroundColor: AppColors.primaryBackground,
actions: [
PopupMenuButton<String>(
color: AppColors.secondaryBackground,
icon: const Icon(Icons.more_vert),
onSelected: (String result) {
// Handle the action based on the selected value
switch (result) {
case 'edit':
// Handle edit action
break;
case 'delete':
_deleteCommunity();
break;
// Add more cases as needed
}
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: 'edit',
child: Text('Edit Group'),
),
const PopupMenuItem<String>(
value: 'delete',
child: Text('Delete Group'),
),
// Add more items as needed
],
),
],
),
backgroundColor: AppColors.secondaryBackground,
body: StreamBuilder<AmityCommunity>(
stream: widget.community.listen.stream,
initialData: widget.community,
builder: (context, snapshot) {
var memberCount = snapshot.data!.membersCount!;
return memberCount > 1
? SingleChildScrollView(
child: Column(
children: [
_buildHeader(),
_buildMemberSection(),
_buildMonthlyRecap(),
const SizedBox(height: 6),
// Add other sections here as needed
],
),
)
: Column(
children: [
_buildHeader(),
_buildNoMembersInviteWidget(),
],
);
},
),
),