🐛 Fix dozens bugs
This commit is contained in:
@@ -131,8 +131,10 @@ class FileListView extends HookConsumerWidget {
|
||||
FileListMode.unindexed => PaginationWidget(
|
||||
provider: unindexedFileListNotifierProvider,
|
||||
notifier: unindexedFileListNotifierProvider.notifier,
|
||||
isRefreshable: false,
|
||||
isSliver: true,
|
||||
contentBuilder:
|
||||
(data) =>
|
||||
(data, footer) =>
|
||||
data.isEmpty
|
||||
? SliverToBoxAdapter(
|
||||
child: _buildEmptyUnindexedFilesHint(ref),
|
||||
@@ -145,13 +147,16 @@ class FileListView extends HookConsumerWidget {
|
||||
isSelectionMode,
|
||||
selectedFileIds,
|
||||
currentVisibleItems,
|
||||
footer,
|
||||
),
|
||||
),
|
||||
_ => PaginationWidget(
|
||||
provider: indexedCloudFileListNotifierProvider,
|
||||
notifier: indexedCloudFileListNotifierProvider.notifier,
|
||||
isRefreshable: false,
|
||||
isSliver: true,
|
||||
contentBuilder:
|
||||
(data) =>
|
||||
(data, footer) =>
|
||||
data.isEmpty
|
||||
? SliverToBoxAdapter(
|
||||
child: _buildEmptyDirectoryHint(ref, currentPath),
|
||||
@@ -165,6 +170,7 @@ class FileListView extends HookConsumerWidget {
|
||||
isSelectionMode,
|
||||
selectedFileIds,
|
||||
currentVisibleItems,
|
||||
footer,
|
||||
),
|
||||
),
|
||||
};
|
||||
@@ -567,6 +573,7 @@ class FileListView extends HookConsumerWidget {
|
||||
ValueNotifier<bool> isSelectionMode,
|
||||
ValueNotifier<Set<String>> selectedFileIds,
|
||||
ValueNotifier<List<FileListItem>> currentVisibleItems,
|
||||
Widget footer,
|
||||
) {
|
||||
currentVisibleItems.value = items;
|
||||
return switch (currentViewMode.value) {
|
||||
@@ -578,7 +585,10 @@ class FileListView extends HookConsumerWidget {
|
||||
crossAxisSpacing: 8,
|
||||
mainAxisSpacing: 8,
|
||||
delegate: SliverChildBuilderDelegate((context, index) {
|
||||
if (index >= items.length) {
|
||||
if (index == items.length) {
|
||||
return footer;
|
||||
}
|
||||
if (index > items.length) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
@@ -609,12 +619,15 @@ class FileListView extends HookConsumerWidget {
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
);
|
||||
}, childCount: items.length),
|
||||
}, childCount: items.length + 1),
|
||||
),
|
||||
// ListView mode
|
||||
_ => SliverList.builder(
|
||||
itemCount: items.length,
|
||||
itemCount: items.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == items.length) {
|
||||
return footer;
|
||||
}
|
||||
final item = items[index];
|
||||
return item.map(
|
||||
file:
|
||||
@@ -1006,6 +1019,7 @@ class FileListView extends HookConsumerWidget {
|
||||
ValueNotifier<bool> isSelectionMode,
|
||||
ValueNotifier<Set<String>> selectedFileIds,
|
||||
ValueNotifier<List<FileListItem>> currentVisibleItems,
|
||||
Widget footer,
|
||||
) {
|
||||
currentVisibleItems.value = items;
|
||||
return switch (currentViewMode.value) {
|
||||
@@ -1017,7 +1031,10 @@ class FileListView extends HookConsumerWidget {
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
delegate: SliverChildBuilderDelegate((context, index) {
|
||||
if (index >= items.length) {
|
||||
if (index == items.length) {
|
||||
return footer;
|
||||
}
|
||||
if (index > items.length) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
@@ -1051,12 +1068,15 @@ class FileListView extends HookConsumerWidget {
|
||||
},
|
||||
),
|
||||
);
|
||||
}, childCount: items.length),
|
||||
}, childCount: items.length + 1),
|
||||
),
|
||||
// ListView mode
|
||||
_ => SliverList.builder(
|
||||
itemCount: items.length,
|
||||
itemCount: items.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == items.length) {
|
||||
return footer;
|
||||
}
|
||||
final item = items[index];
|
||||
return item.map(
|
||||
file: (fileItem) {
|
||||
|
||||
@@ -1,59 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:island/pods/paging.dart';
|
||||
|
||||
import 'package:island/widgets/extended_refresh_indicator.dart';
|
||||
import 'package:island/widgets/response.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:super_sliver_list/super_sliver_list.dart';
|
||||
import 'package:visibility_detector/visibility_detector.dart';
|
||||
|
||||
class PaginationList<T> extends HookConsumerWidget {
|
||||
final ProviderListenable<AsyncValue<List<T>>> provider;
|
||||
final Refreshable<PaginationController<T>> notifier;
|
||||
final Widget? Function(BuildContext, int, T) itemBuilder;
|
||||
final bool isRefreshable;
|
||||
final bool isSliver;
|
||||
final bool showDefaultWidgets;
|
||||
const PaginationList({
|
||||
super.key,
|
||||
required this.provider,
|
||||
required this.notifier,
|
||||
required this.itemBuilder,
|
||||
this.isRefreshable = true,
|
||||
this.isSliver = false,
|
||||
this.showDefaultWidgets = true,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final data = ref.watch(provider);
|
||||
final noti = ref.watch(notifier);
|
||||
final listView = SuperListView.builder(
|
||||
itemBuilder: (context, idx) {
|
||||
final entry = data.valueOrNull?[idx];
|
||||
if (entry != null) return itemBuilder(context, idx, entry);
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final child = NotificationListener(
|
||||
onNotification: (ScrollNotification scrollInfo) {
|
||||
if (scrollInfo is ScrollEndNotification &&
|
||||
scrollInfo.metrics.axisDirection == AxisDirection.down &&
|
||||
scrollInfo.metrics.pixels >= scrollInfo.metrics.maxScrollExtent) {
|
||||
if (!noti.fetchedAll && !data.isLoading && !data.hasError) {
|
||||
noti.fetchFurther();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
child: listView,
|
||||
);
|
||||
if (data.isLoading && data.valueOrNull?.isEmpty == true) {
|
||||
final content = ResponseLoadingWidget();
|
||||
return isSliver ? SliverFillRemaining(child: content) : content;
|
||||
}
|
||||
|
||||
if (data.hasError) {
|
||||
final content = ResponseErrorWidget(
|
||||
error: data.error,
|
||||
onRetry: noti.refresh,
|
||||
);
|
||||
return isSliver ? SliverFillRemaining(child: content) : content;
|
||||
}
|
||||
|
||||
final listView =
|
||||
isSliver
|
||||
? SuperSliverList.builder(
|
||||
itemCount: (data.valueOrNull?.length ?? 0) + 1,
|
||||
itemBuilder: (context, idx) {
|
||||
if (idx == data.valueOrNull?.length) {
|
||||
return PaginationListFooter(noti: noti, data: data);
|
||||
}
|
||||
final entry = data.valueOrNull?[idx];
|
||||
if (entry != null) return itemBuilder(context, idx, entry);
|
||||
return null;
|
||||
},
|
||||
)
|
||||
: SuperListView.builder(
|
||||
itemCount: (data.valueOrNull?.length ?? 0) + 1,
|
||||
itemBuilder: (context, idx) {
|
||||
if (idx == data.valueOrNull?.length) {
|
||||
return PaginationListFooter(noti: noti, data: data);
|
||||
}
|
||||
final entry = data.valueOrNull?[idx];
|
||||
if (entry != null) return itemBuilder(context, idx, entry);
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
return isRefreshable
|
||||
? ExtendedRefreshIndicator(onRefresh: noti.refresh, child: child)
|
||||
: child;
|
||||
? ExtendedRefreshIndicator(onRefresh: noti.refresh, child: listView)
|
||||
: listView;
|
||||
}
|
||||
}
|
||||
|
||||
class PaginationWidget<T> extends HookConsumerWidget {
|
||||
final ProviderListenable<AsyncValue<List<T>>> provider;
|
||||
final Refreshable<PaginationController<T>> notifier;
|
||||
final Widget Function(List<T>) contentBuilder;
|
||||
final Widget Function(List<T>, Widget) contentBuilder;
|
||||
final bool isRefreshable;
|
||||
final bool isSliver;
|
||||
final bool showDefaultWidgets;
|
||||
@@ -72,7 +96,7 @@ class PaginationWidget<T> extends HookConsumerWidget {
|
||||
final data = ref.watch(provider);
|
||||
final noti = ref.watch(notifier);
|
||||
|
||||
if (data.isLoading) {
|
||||
if (data.isLoading && data.valueOrNull?.isEmpty == true) {
|
||||
final content = ResponseLoadingWidget();
|
||||
return isSliver ? SliverFillRemaining(child: content) : content;
|
||||
}
|
||||
@@ -85,22 +109,42 @@ class PaginationWidget<T> extends HookConsumerWidget {
|
||||
return isSliver ? SliverFillRemaining(child: content) : content;
|
||||
}
|
||||
|
||||
final content = NotificationListener(
|
||||
onNotification: (ScrollNotification scrollInfo) {
|
||||
if (scrollInfo is ScrollEndNotification &&
|
||||
scrollInfo.metrics.axisDirection == AxisDirection.down &&
|
||||
scrollInfo.metrics.pixels >= scrollInfo.metrics.maxScrollExtent) {
|
||||
if (!noti.fetchedAll && !data.isLoading && !data.hasError) {
|
||||
noti.fetchFurther();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
child: contentBuilder(data.valueOrNull ?? []),
|
||||
);
|
||||
final footer = PaginationListFooter(noti: noti, data: data);
|
||||
final content = contentBuilder(data.valueOrNull ?? [], footer);
|
||||
|
||||
return isRefreshable
|
||||
? ExtendedRefreshIndicator(onRefresh: noti.refresh, child: content)
|
||||
: content;
|
||||
}
|
||||
}
|
||||
|
||||
class PaginationListFooter<T> extends StatelessWidget {
|
||||
final PaginationController<T> noti;
|
||||
final AsyncValue<List<T>> data;
|
||||
final bool isSliver;
|
||||
|
||||
const PaginationListFooter({
|
||||
super.key,
|
||||
required this.noti,
|
||||
required this.data,
|
||||
this.isSliver = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final child = SizedBox(
|
||||
height: 64,
|
||||
child: Center(child: CircularProgressIndicator()).padding(all: 8),
|
||||
);
|
||||
|
||||
return VisibilityDetector(
|
||||
key: Key("pagination-list-${noti.hashCode}"),
|
||||
onVisibilityChanged: (VisibilityInfo info) {
|
||||
if (!noti.fetchedAll && !data.isLoading && !data.hasError) {
|
||||
noti.fetchFurther();
|
||||
}
|
||||
},
|
||||
child: isSliver ? SliverToBoxAdapter(child: child) : child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user