Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ud-SDK-Flutter-Sample-App into ws/feat/filter-deleted-user

# Conflicts:
#	lib/presentation/screen/community_list/community_list_screen.dart
  • Loading branch information
kornsitti committed Jul 26, 2024
2 parents ce6157b + df4a75b commit adc73db
Showing 1 changed file with 140 additions and 176 deletions.
316 changes: 140 additions & 176 deletions lib/presentation/screen/community_list/community_list_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:developer';

import 'package:amity_sdk/amity_sdk.dart';
import 'package:flutter/material.dart';
import 'package:flutter_social_sample_app/core/route/app_route.dart';
Expand All @@ -16,9 +14,7 @@ class CommunityListScreen extends StatefulWidget {
}

class _CommunityListScreenState extends State<CommunityListScreen> {
// var amityCommunities = <AmityCommunity>[];
final List<AmityCommunity> _amityCommunities = [];
final List<AmityCommunity> _amityCommunitiesForFeed = [];
var amityCommunities = <AmityCommunity>[];

final scrollcontroller = ScrollController();
bool loading = false;
Expand All @@ -37,14 +33,11 @@ class _CommunityListScreenState extends State<CommunityListScreen> {

@override
void initState() {

communityLiveCollectionInit();
initMyCommunity();
super.initState();
}

void communityLiveCollectionInit() {

void communityLiveCollectionInit() {
communityLiveCollection = CommunityLiveCollection(
request: () => AmitySocialClient.newCommunityRepository()
.getCommunities()
Expand All @@ -55,61 +48,24 @@ class _CommunityListScreenState extends State<CommunityListScreen> {
.includeDeleted(_includeDelete)
.build());


// communityLiveCollection.getStreamController().stream.listen((event) {
// if (mounted) {
// setState(() {
// amityCommunities = event;
// });
// }
// });

WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
communityLiveCollection.loadNext();
});

scrollcontroller.addListener(pagination);
}

Future<void> initMyCommunity([String? keyword]) async {
final repository = AmitySocialClient.newCommunityRepository()
.getCommunities()
.filter(AmityCommunityFilter.MEMBER)
.includeDeleted(false);
if (keyword != null && keyword.isNotEmpty) {
repository.withKeyword(
keyword); // Add keyword filtering only if keyword is provided and not empty
}
communityLiveCollection = repository.getLiveCollection(pageSize: 20);
communityLiveCollection.getStreamController().stream.listen((event) {
print("getStreamController");
_amityCommunitiesForFeed.clear();
_amityCommunitiesForFeed.addAll(event);

_amityCommunities.clear();
_amityCommunities.addAll(event);

setState(() {

});

}).onError((error, stackTrace) {
log("error:${error.error.toString()}");
// await AmityDialog().showAlertErrorDialog(
// title: "Error!",
// message: _communityController.error.toString());
if (mounted) {
setState(() {
amityCommunities = event;
});
}
});

scrollcontroller.removeListener(() {});
scrollcontroller.addListener(pagination);
}

void pagination() {
if ((scrollcontroller.position.pixels ==
scrollcontroller.position.maxScrollExtent) &&
communityLiveCollection.hasNextPage()) {
communityLiveCollection.loadNext();
}
scrollcontroller.position.maxScrollExtent) &&
communityLiveCollection.hasNextPage()) {
print("TriggerPagination");
communityLiveCollection.loadNext();
}
}

@override
Expand All @@ -124,147 +80,155 @@ class _CommunityListScreenState extends State<CommunityListScreen> {
onChanged: (value) {
_debouncer.run(() {
_keyboard = value;
communityLiveCollection.reset();
communityLiveCollectionInit();
});
},
decoration: const InputDecoration(hintText: 'Enter Keybaord'),
),
),
Container(
child: Row(
children: [
Container(
padding: const EdgeInsets.all(8),
child: PopupMenuButton(
itemBuilder: (context) {
return [
PopupMenuItem(
value: 1,
child: Text(AmityCommunityFilter.ALL.name),
),
PopupMenuItem(
value: 2,
child: Text(AmityCommunityFilter.MEMBER.name),
),
PopupMenuItem(
value: 3,
child: Text(AmityCommunityFilter.NOT_MEMBER.name),
)
];
},
child: const Icon(
Icons.filter_alt_rounded,
size: 18,
),
onSelected: (index) {
if (index == 1) {
_filter = AmityCommunityFilter.ALL;
}
if (index == 2) {
_filter = AmityCommunityFilter.MEMBER;
}
if (index == 3) {
_filter = AmityCommunityFilter.NOT_MEMBER;
}

communityLiveCollection.reset();
communityLiveCollectionInit();
},
Row(
children: [
Container(
padding: const EdgeInsets.all(8),
child: PopupMenuButton(
itemBuilder: (context) {
return [
PopupMenuItem(
value: 1,
child: Text(AmityCommunityFilter.ALL.name),
),
PopupMenuItem(
value: 2,
child: Text(AmityCommunityFilter.MEMBER.name),
),
PopupMenuItem(
value: 3,
child: Text(AmityCommunityFilter.NOT_MEMBER.name),
)
];
},
child: const Icon(
Icons.filter_alt_rounded,
size: 18,
),
onSelected: (index) {
if (index == 1) {
_filter = AmityCommunityFilter.ALL;
}
if (index == 2) {
_filter = AmityCommunityFilter.MEMBER;
}
if (index == 3) {
_filter = AmityCommunityFilter.NOT_MEMBER;
}
},
),
Container(
padding: const EdgeInsets.all(8),
child: PopupMenuButton(
itemBuilder: (context) {
return [
PopupMenuItem(

child: Text(AmityCommunitySortOption.DISPLAY_NAME.name),
value: 1,
),
PopupMenuItem(
child: Text(AmityCommunitySortOption.FIRST_CREATED.name),
value: 2,
),
PopupMenuItem(
child: Text(AmityCommunitySortOption.LAST_CREATED.name),
value: 3,
)
];
},
child: const Icon(
Icons.sort_rounded,
size: 18,
),
onSelected: (index) {
if (index == 1) {
_sort = AmityCommunitySortOption.DISPLAY_NAME;
}
if (index == 2) {
_sort = AmityCommunitySortOption.FIRST_CREATED;
}
if (index == 3) {
_sort = AmityCommunitySortOption.LAST_CREATED;
}
communityLiveCollection.reset();
communityLiveCollectionInit();
},
),
Container(
padding: const EdgeInsets.all(8),
child: PopupMenuButton(
itemBuilder: (context) {
return [
PopupMenuItem(
value: 1,
child:
Text(AmityCommunitySortOption.DISPLAY_NAME.name),
),
PopupMenuItem(
value: 2,
child:
Text(AmityCommunitySortOption.FIRST_CREATED.name),
),
PopupMenuItem(
value: 3,
child:
Text(AmityCommunitySortOption.LAST_CREATED.name),
)
];
},
child: const Icon(
Icons.sort_rounded,
size: 18,
),
onSelected: (index) {
if (index == 1) {
_sort = AmityCommunitySortOption.DISPLAY_NAME;
}
if (index == 2) {
_sort = AmityCommunitySortOption.FIRST_CREATED;
}
if (index == 3) {
_sort = AmityCommunitySortOption.LAST_CREATED;
}
},
),
Container(
padding: const EdgeInsets.all(8),
child: InkWell(
child: const Icon(Icons.tag, size: 18),
onTap: () {
EditTextDialog.show(context, title: 'Enter tags, separate by comma', hintText: 'type tags here',
onPress: (value) {
if (value.isNotEmpty) {
_tags = value.trim().split(',');
} else {
_tags = null;
}
),
Container(
padding: const EdgeInsets.all(8),
child: InkWell(
child: const Icon(Icons.tag, size: 18),
onTap: () {
EditTextDialog.show(context,
title: 'Enter tags, separate by comma',
hintText: 'type tags here', onPress: (value) {
if (value.isNotEmpty) {
_tags = value.trim().split(',');
} else {
_tags = null;
}
});
},
),
),
Container(
padding: const EdgeInsets.all(8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Checkbox(
value: _includeDelete,
onChanged: (value) {
setState(() {
_includeDelete = (value ?? false);
});
},
),
const Text('Include Delete')
],
),
),
Container(
padding: const EdgeInsets.all(8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton(
onPressed: () {
communityLiveCollection.reset();
communityLiveCollectionInit();
});
},
),
),
Container(
padding: const EdgeInsets.all(8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Checkbox(
value: _includeDelete,
onChanged: (value) {
setState(() {
_includeDelete = (value ?? false);
communityLiveCollection.reset();

communityLiveCollectionInit();
});
},
communityLiveCollection.loadNext();
},
child: const Text(
"Query",
),
const Text('Include Delete')
],
),
)
],
),
)
],
),
)
],
),
Expanded(
child: _amityCommunities.isNotEmpty
child: amityCommunities.isNotEmpty
? RefreshIndicator(
onRefresh: () async {
communityLiveCollection.reset();
communityLiveCollectionInit();
communityLiveCollection.loadNext();
},
child: ListView.builder(
controller: scrollcontroller,
itemCount: _amityCommunities.length,
itemCount: amityCommunities.length,
itemBuilder: (context, index) {
final amityCommunity = _amityCommunities[index];
final amityCommunity = amityCommunities[index];
return Container(
margin: const EdgeInsets.all(12),
child: CommunityWidget(
Expand All @@ -286,7 +250,7 @@ class _CommunityListScreenState extends State<CommunityListScreen> {
: const Text('No Post'),
),
),
if (_amityCommunities.isNotEmpty && communityLiveCollection.isFetching)
if (amityCommunities.isNotEmpty && communityLiveCollection.isFetching)
Container(
alignment: Alignment.center,
child: const CircularProgressIndicator(),
Expand Down

0 comments on commit adc73db

Please sign in to comment.