mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
Refactor notification handling in SidebarCommunitiesList for improved readability and maintainability.
This commit is contained in:
@ -16,6 +16,16 @@ class SidebarCommunitiesList extends StatelessWidget {
|
|||||||
final ScrollController scrollController;
|
final ScrollController scrollController;
|
||||||
final void Function() onScrollToEnd;
|
final void Function() onScrollToEnd;
|
||||||
|
|
||||||
|
bool _onNotification(ScrollEndNotification notification) {
|
||||||
|
final hasReachedEnd = notification.metrics.extentAfter == 0;
|
||||||
|
if (hasReachedEnd) {
|
||||||
|
onScrollToEnd.call();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
@ -26,17 +36,11 @@ class SidebarCommunitiesList extends StatelessWidget {
|
|||||||
scrollbarOrientation: ScrollbarOrientation.left,
|
scrollbarOrientation: ScrollbarOrientation.left,
|
||||||
thumbVisibility: true,
|
thumbVisibility: true,
|
||||||
controller: scrollController,
|
controller: scrollController,
|
||||||
child: NotificationListener(
|
child: NotificationListener<ScrollEndNotification>(
|
||||||
onNotification: (notification) {
|
onNotification: _onNotification,
|
||||||
if (notification is ScrollEndNotification &&
|
|
||||||
notification.metrics.extentAfter == 0) {
|
|
||||||
onScrollToEnd.call();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
padding: const EdgeInsetsDirectional.only(start: 16),
|
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
|
padding: const EdgeInsetsDirectional.only(start: 16),
|
||||||
itemCount: communities.length,
|
itemCount: communities.length,
|
||||||
controller: scrollController,
|
controller: scrollController,
|
||||||
itemBuilder: itemBuilder,
|
itemBuilder: itemBuilder,
|
||||||
|
Reference in New Issue
Block a user