Skip to content

Commit

Permalink
Um/asc 18524/internal flutter ver 0.30.0 error when check user role (#…
Browse files Browse the repository at this point in the history
…204)

* Added Current User community roles to be displayed

* Added Roles support to Community profile
  • Loading branch information
umareko authored Dec 11, 2023
1 parent 18d353b commit 3b5a1d1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ class _CommunityProfileScreenState extends State<CommunityProfileScreen> with Ti
late AmityCommunity _amityCommunity;
Future<AmityCommunity>? _future;



GlobalKey<CommunityMemberScreenState> memberList = GlobalKey<CommunityMemberScreenState>();
@override
void initState() {
void initState() {
_tabController = TabController(length: 3, vsync: this);


_future = AmitySocialClient.newCommunityRepository().getCommunity(widget.communityId);
super.initState();

}

@override
Expand Down Expand Up @@ -237,9 +241,26 @@ class _CommunityProfileScreenState extends State<CommunityProfileScreen> with Ti
}
}

class _CommunityProfileHeaderWidget extends StatelessWidget {
class _CommunityProfileHeaderWidget extends StatefulWidget {
const _CommunityProfileHeaderWidget({Key? key, required this.amityCommunity}) : super(key: key);
final AmityCommunity amityCommunity;

@override
State<_CommunityProfileHeaderWidget> createState() => _CommunityProfileHeaderWidgetState();
}

class _CommunityProfileHeaderWidgetState extends State<_CommunityProfileHeaderWidget> {
Future<List<String>?>? _rolesFuture;

@override
void initState() {
if(widget.amityCommunity.communityId!=null){
_rolesFuture = AmitySocialClient.newCommunityRepository().getCurrentUserRoles(widget.amityCommunity.communityId!);
}
super.initState();
}


@override
Widget build(BuildContext context) {
final themeData = Theme.of(context);
Expand All @@ -255,9 +276,9 @@ class _CommunityProfileHeaderWidget extends StatelessWidget {
height: 64,
decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.grey.withOpacity(.3)),
clipBehavior: Clip.antiAliasWithSaveLayer,
child: amityCommunity.avatarImage?.getUrl(AmityImageSize.MEDIUM) != null
child: widget.amityCommunity.avatarImage?.getUrl(AmityImageSize.MEDIUM) != null
? Image.network(
amityCommunity.avatarImage!.getUrl(AmityImageSize.MEDIUM),
widget.amityCommunity.avatarImage!.getUrl(AmityImageSize.MEDIUM),
fit: BoxFit.fill,
)
: Image.asset('assets/user_placeholder.png'),
Expand All @@ -272,7 +293,7 @@ class _CommunityProfileHeaderWidget extends StatelessWidget {
text: TextSpan(
children: [
TextSpan(
text: '${amityCommunity.postsCount}\n',
text: '${widget.amityCommunity.postsCount}\n',
style: themeData.textTheme.titleMedium!.copyWith(fontWeight: FontWeight.bold),
),
TextSpan(text: 'Posts', style: themeData.textTheme.bodyMedium),
Expand All @@ -284,7 +305,7 @@ class _CommunityProfileHeaderWidget extends StatelessWidget {
text: TextSpan(
children: [
TextSpan(
text: '${amityCommunity.membersCount}\n',
text: '${widget.amityCommunity.membersCount}\n',
style: themeData.textTheme.titleMedium!.copyWith(fontWeight: FontWeight.bold),
),
TextSpan(text: 'Members', style: themeData.textTheme.bodyMedium),
Expand All @@ -298,25 +319,20 @@ class _CommunityProfileHeaderWidget extends StatelessWidget {
),
const SizedBox(height: 10),
Text(
amityCommunity.displayName ?? '',
widget.amityCommunity.displayName ?? '',
style: themeData.textTheme.titleLarge,
),
const SizedBox(height: 8),
Text(
amityCommunity.description ?? '',
widget.amityCommunity.description ?? '',
style: themeData.textTheme.bodySmall,
),
const SizedBox(height: 18),
FutureBuilder<List<String>>(
future: amityCommunity.getCurentUserRoles(),
FutureBuilder<List<String>?>(
future: _rolesFuture,
builder: (context, snapshot) {
if (snapshot.hasData) {
return Text('Rolse - ${snapshot.data!.join(',')}');
}
if (snapshot.hasError) {
// print(snapshot.error.toString());
}
return Container();
var currentUserRoles = snapshot.data;
return Text("Current User Roles: ${currentUserRoles ?? "Not A member"}");
},
),
const SizedBox(height: 18),
Expand All @@ -325,36 +341,36 @@ class _CommunityProfileHeaderWidget extends StatelessWidget {
width: 260,
child: ElevatedButton(
onPressed: () {
if (!(amityCommunity.isJoined ?? true)) {
if (!(widget.amityCommunity.isJoined ?? true)) {
AmitySocialClient.newCommunityRepository()
.joinCommunity(amityCommunity.communityId!)
.joinCommunity(widget.amityCommunity.communityId!)
.then((value) {})
.onError((error, stackTrace) {
ErrorDialog.show(context, title: 'Error', message: error.toString());
});
} else {
AmitySocialClient.newCommunityRepository()
.leaveCommunity(amityCommunity.communityId!)
.leaveCommunity(widget.amityCommunity.communityId!)
.then((value) {})
.onError((error, stackTrace) {
ErrorDialog.show(context, title: 'Error', message: error.toString());
});
}
},
child: Text(!(amityCommunity.isJoined ?? true) ? 'Join' : 'Leave'),
child: Text(!(widget.amityCommunity.isJoined ?? true) ? 'Join' : 'Leave'),
),
),
),
if (amityCommunity.hasPermission(AmityPermission.REVIEW_COMMUNITY_POST) &&
amityCommunity.isPostReviewEnabled!)
if (widget.amityCommunity.hasPermission(AmityPermission.REVIEW_COMMUNITY_POST) &&
widget.amityCommunity.isPostReviewEnabled!)
Center(
child: SizedBox(
width: 260,
child: ElevatedButton(
onPressed: () {
GoRouter.of(context).pushNamed(AppRoute.communityInReviewPost, queryParams: {
'communityId': amityCommunity.communityId,
'isPublic': amityCommunity.isPublic!.toString()
'communityId': widget.amityCommunity.communityId,
'isPublic': widget.amityCommunity.isPublic!.toString()
});
},
child: const Text('Review Post'),
Expand All @@ -368,15 +384,15 @@ class _CommunityProfileHeaderWidget extends StatelessWidget {
child: ElevatedButton(
onPressed: () {
GoRouter.of(context).pushNamed(AppRoute.communityPendingPost, queryParams: {
'communityId': amityCommunity.communityId,
'isPublic': amityCommunity.isPublic!.toString()
'communityId': widget.amityCommunity.communityId,
'isPublic': widget.amityCommunity.isPublic!.toString()
});
},
child: const Text('Pending Post'),
),
),
),
RawDataWidget(jsonRawData: amityCommunity.toJson()),
RawDataWidget(jsonRawData: widget.amityCommunity.toJson()),
],
),
);
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: flutter_social_sample_app
description: Demonstrates how to use the flutter_application_1 plugin.

version: 1.1.5+20
version: 1.1.7+22

environment:
sdk: ">=2.17.0 <3.0.0"
Expand Down Expand Up @@ -38,7 +38,7 @@ dependencies:

universal_html: ^2.2.3
url_launcher: ^6.0.20
uuid: ^4.2.1
uuid: ^3.0.6
video_player: ^2.3.0


Expand Down

0 comments on commit 3b5a1d1

Please sign in to comment.