🐛 Fix dozens bugs
This commit is contained in:
@@ -39,7 +39,7 @@ mixin AsyncPaginationController<T> on AsyncNotifier<List<T>>
|
|||||||
Future<void> refresh() async {
|
Future<void> refresh() async {
|
||||||
totalCount = null;
|
totalCount = null;
|
||||||
fetchedCount = 0;
|
fetchedCount = 0;
|
||||||
state = AsyncLoading<List<T>>();
|
state = AsyncData<List<T>>([]);
|
||||||
|
|
||||||
final newState = await AsyncValue.guard<List<T>>(() async {
|
final newState = await AsyncValue.guard<List<T>>(() async {
|
||||||
return await fetch();
|
return await fetch();
|
||||||
@@ -74,7 +74,7 @@ mixin AsyncPaginationFilter<F, T> on AsyncPaginationController<T>
|
|||||||
fetchedCount = 0;
|
fetchedCount = 0;
|
||||||
currentFilter = filter;
|
currentFilter = filter;
|
||||||
|
|
||||||
state = AsyncLoading<List<T>>();
|
state = AsyncData<List<T>>([]);
|
||||||
|
|
||||||
final newState = await AsyncValue.guard<List<T>>(() async {
|
final newState = await AsyncValue.guard<List<T>>(() async {
|
||||||
return await fetch();
|
return await fetch();
|
||||||
|
|||||||
@@ -23,11 +23,7 @@ class ActivityListNotifier extends AsyncNotifier<List<SnTimelineEvent>>
|
|||||||
final client = ref.read(apiClientProvider);
|
final client = ref.read(apiClientProvider);
|
||||||
|
|
||||||
final cursor =
|
final cursor =
|
||||||
state.isLoading
|
state.valueOrNull?.lastOrNull?.createdAt.toUtc().toIso8601String();
|
||||||
? null
|
|
||||||
: state.valueOrNull?.lastOrNull?.createdAt
|
|
||||||
.toUtc()
|
|
||||||
.toIso8601String();
|
|
||||||
|
|
||||||
final queryParameters = {
|
final queryParameters = {
|
||||||
if (cursor != null) 'cursor': cursor,
|
if (cursor != null) 'cursor': cursor,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:gap/gap.dart';
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:island/models/account.dart';
|
import 'package:island/models/account.dart';
|
||||||
import 'package:island/pods/network.dart';
|
import 'package:island/pods/network.dart';
|
||||||
|
import 'package:island/pods/paging.dart';
|
||||||
import 'package:island/pods/userinfo.dart';
|
import 'package:island/pods/userinfo.dart';
|
||||||
import 'package:island/screens/account/credits.dart';
|
import 'package:island/screens/account/credits.dart';
|
||||||
import 'package:island/services/time.dart';
|
import 'package:island/services/time.dart';
|
||||||
@@ -10,46 +11,37 @@ import 'package:island/widgets/account/leveling_progress.dart';
|
|||||||
import 'package:island/widgets/account/stellar_program_tab.dart';
|
import 'package:island/widgets/account/stellar_program_tab.dart';
|
||||||
import 'package:island/widgets/app_scaffold.dart';
|
import 'package:island/widgets/app_scaffold.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
import 'package:island/widgets/paging/pagination_list.dart';
|
||||||
import 'package:riverpod_paging_utils/riverpod_paging_utils.dart';
|
|
||||||
import 'package:styled_widget/styled_widget.dart';
|
import 'package:styled_widget/styled_widget.dart';
|
||||||
|
|
||||||
part 'leveling.g.dart';
|
final levelingHistoryNotifierProvider = AsyncNotifierProvider(
|
||||||
|
LevelingHistoryNotifier.new,
|
||||||
|
);
|
||||||
|
|
||||||
@riverpod
|
class LevelingHistoryNotifier extends AsyncNotifier<List<SnExperienceRecord>>
|
||||||
class LevelingHistoryNotifier extends _$LevelingHistoryNotifier
|
with AsyncPaginationController<SnExperienceRecord> {
|
||||||
with CursorPagingNotifierMixin<SnExperienceRecord> {
|
static const int pageSize = 20;
|
||||||
static const int _pageSize = 20;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<CursorPagingData<SnExperienceRecord>> build() => fetch(cursor: null);
|
Future<List<SnExperienceRecord>> fetch() async {
|
||||||
|
|
||||||
@override
|
|
||||||
Future<CursorPagingData<SnExperienceRecord>> fetch({
|
|
||||||
required String? cursor,
|
|
||||||
}) async {
|
|
||||||
final client = ref.read(apiClientProvider);
|
final client = ref.read(apiClientProvider);
|
||||||
final offset = cursor == null ? 0 : int.parse(cursor);
|
|
||||||
|
|
||||||
final queryParams = {'offset': offset, 'take': _pageSize};
|
final queryParams = {'offset': fetchedCount.toString(), 'take': pageSize};
|
||||||
|
|
||||||
final response = await client.get(
|
final response = await client.get(
|
||||||
'/pass/accounts/me/leveling',
|
'/pass/accounts/me/leveling',
|
||||||
queryParameters: queryParams,
|
queryParameters: queryParams,
|
||||||
);
|
);
|
||||||
final total = int.parse(response.headers.value('X-Total') ?? '0');
|
|
||||||
final List<dynamic> data = response.data;
|
|
||||||
final records =
|
|
||||||
data.map((json) => SnExperienceRecord.fromJson(json)).toList();
|
|
||||||
|
|
||||||
final hasMore = offset + records.length < total;
|
totalCount = int.parse(response.headers.value('X-Total') ?? '0');
|
||||||
final nextCursor = hasMore ? (offset + records.length).toString() : null;
|
|
||||||
|
|
||||||
return CursorPagingData(
|
final List<SnExperienceRecord> records =
|
||||||
items: records,
|
response.data
|
||||||
hasMore: hasMore,
|
.map((json) => SnExperienceRecord.fromJson(json))
|
||||||
nextCursor: nextCursor,
|
.cast<SnExperienceRecord>()
|
||||||
);
|
.toList();
|
||||||
|
|
||||||
|
return records;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,19 +181,13 @@ class LevelingScreen extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SliverGap(8),
|
const SliverGap(8),
|
||||||
PagingHelperSliverView(
|
PaginationList(
|
||||||
provider: levelingHistoryNotifierProvider,
|
provider: levelingHistoryNotifierProvider,
|
||||||
futureRefreshable: levelingHistoryNotifierProvider.future,
|
notifier: levelingHistoryNotifierProvider.notifier,
|
||||||
notifierRefreshable: levelingHistoryNotifierProvider.notifier,
|
isRefreshable: false,
|
||||||
contentBuilder:
|
isSliver: true,
|
||||||
(data, widgetCount, endItemView) => SliverList.builder(
|
itemBuilder:
|
||||||
itemCount: widgetCount,
|
(context, idx, record) => ListTile(
|
||||||
itemBuilder: (context, index) {
|
|
||||||
if (index == widgetCount - 1) {
|
|
||||||
return endItemView;
|
|
||||||
}
|
|
||||||
final record = data.items[index];
|
|
||||||
return ListTile(
|
|
||||||
title: Column(
|
title: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
@@ -214,9 +200,7 @@ class LevelingScreen extends HookConsumerWidget {
|
|||||||
record.createdAt.formatRelative(context),
|
record.createdAt.formatRelative(context),
|
||||||
).fontSize(13),
|
).fontSize(13),
|
||||||
Text('·').fontSize(13).bold(),
|
Text('·').fontSize(13).bold(),
|
||||||
Text(
|
Text(record.createdAt.formatSystem()).fontSize(13),
|
||||||
record.createdAt.formatSystem(),
|
|
||||||
).fontSize(13),
|
|
||||||
],
|
],
|
||||||
).opacity(0.8),
|
).opacity(0.8),
|
||||||
],
|
],
|
||||||
@@ -233,8 +217,6 @@ class LevelingScreen extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
minTileHeight: 56,
|
minTileHeight: 56,
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 4),
|
contentPadding: EdgeInsets.symmetric(horizontal: 4),
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
|
|
||||||
part of 'leveling.dart';
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// RiverpodGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
String _$levelingHistoryNotifierHash() =>
|
|
||||||
r'de51012e1590ac46388b6f3f2050b21cb96698d1';
|
|
||||||
|
|
||||||
/// See also [LevelingHistoryNotifier].
|
|
||||||
@ProviderFor(LevelingHistoryNotifier)
|
|
||||||
final levelingHistoryNotifierProvider = AutoDisposeAsyncNotifierProvider<
|
|
||||||
LevelingHistoryNotifier,
|
|
||||||
CursorPagingData<SnExperienceRecord>
|
|
||||||
>.internal(
|
|
||||||
LevelingHistoryNotifier.new,
|
|
||||||
name: r'levelingHistoryNotifierProvider',
|
|
||||||
debugGetCreateSourceHash:
|
|
||||||
const bool.fromEnvironment('dart.vm.product')
|
|
||||||
? null
|
|
||||||
: _$levelingHistoryNotifierHash,
|
|
||||||
dependencies: null,
|
|
||||||
allTransitiveDependencies: null,
|
|
||||||
);
|
|
||||||
|
|
||||||
typedef _$LevelingHistoryNotifier =
|
|
||||||
AutoDisposeAsyncNotifier<CursorPagingData<SnExperienceRecord>>;
|
|
||||||
// ignore_for_file: type=lint
|
|
||||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
|
|
||||||
@@ -573,6 +573,7 @@ class CreatorHubScreen extends HookConsumerWidget {
|
|||||||
child: publisherStats.when(
|
child: publisherStats.when(
|
||||||
data:
|
data:
|
||||||
(stats) => SingleChildScrollView(
|
(stats) => SingleChildScrollView(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 24),
|
||||||
child:
|
child:
|
||||||
currentPublisher.value == null
|
currentPublisher.value == null
|
||||||
? ConstrainedBox(
|
? ConstrainedBox(
|
||||||
@@ -602,7 +603,7 @@ class CreatorHubScreen extends HookConsumerWidget {
|
|||||||
).padding(horizontal: 12),
|
).padding(horizontal: 12),
|
||||||
buildNavigationWidget(true),
|
buildNavigationWidget(true),
|
||||||
],
|
],
|
||||||
).padding(vertical: 24)
|
)
|
||||||
: Column(
|
: Column(
|
||||||
spacing: 12,
|
spacing: 12,
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -127,11 +127,14 @@ class ExploreScreen extends HookConsumerWidget {
|
|||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
spacing: 4,
|
spacing: 8,
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => handleFilterChange(null),
|
onPressed: () => handleFilterChange(null),
|
||||||
icon: Icon(Symbols.explore),
|
icon: Icon(
|
||||||
|
Symbols.explore,
|
||||||
|
fill: currentFilter.value == null ? 1 : null,
|
||||||
|
),
|
||||||
tooltip: 'explore'.tr(),
|
tooltip: 'explore'.tr(),
|
||||||
isSelected: currentFilter.value == null,
|
isSelected: currentFilter.value == null,
|
||||||
color:
|
color:
|
||||||
@@ -141,7 +144,10 @@ class ExploreScreen extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => handleFilterChange('subscriptions'),
|
onPressed: () => handleFilterChange('subscriptions'),
|
||||||
icon: Icon(Symbols.subscriptions),
|
icon: Icon(
|
||||||
|
Symbols.subscriptions,
|
||||||
|
fill: currentFilter.value == 'subscriptions' ? 1 : null,
|
||||||
|
),
|
||||||
tooltip: 'exploreFilterSubscriptions'.tr(),
|
tooltip: 'exploreFilterSubscriptions'.tr(),
|
||||||
isSelected: currentFilter.value == 'subscriptions',
|
isSelected: currentFilter.value == 'subscriptions',
|
||||||
color:
|
color:
|
||||||
@@ -151,7 +157,10 @@ class ExploreScreen extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => handleFilterChange('friends'),
|
onPressed: () => handleFilterChange('friends'),
|
||||||
icon: Icon(Symbols.people),
|
icon: Icon(
|
||||||
|
Symbols.people,
|
||||||
|
fill: currentFilter.value == 'friends' ? 1 : null,
|
||||||
|
),
|
||||||
tooltip: 'exploreFilterFriends'.tr(),
|
tooltip: 'exploreFilterFriends'.tr(),
|
||||||
isSelected: currentFilter.value == 'friends',
|
isSelected: currentFilter.value == 'friends',
|
||||||
color:
|
color:
|
||||||
@@ -312,7 +321,9 @@ class ExploreScreen extends HookConsumerWidget {
|
|||||||
// Sliver list cannot provide refresh handled by the pagination list
|
// Sliver list cannot provide refresh handled by the pagination list
|
||||||
isRefreshable: false,
|
isRefreshable: false,
|
||||||
isSliver: true,
|
isSliver: true,
|
||||||
contentBuilder: (data) => _ActivityListView(data: data, isWide: isWide),
|
contentBuilder:
|
||||||
|
(data, footer) =>
|
||||||
|
_ActivityListView(data: data, isWide: isWide, footer: footer),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,31 +439,46 @@ class ExploreScreen extends HookConsumerWidget {
|
|||||||
final foregroundColor = Theme.of(context).appBarTheme.foregroundColor;
|
final foregroundColor = Theme.of(context).appBarTheme.foregroundColor;
|
||||||
|
|
||||||
return AppBar(
|
return AppBar(
|
||||||
toolbarHeight: 48 + 4,
|
toolbarHeight: 48,
|
||||||
flexibleSpace: Container(
|
flexibleSpace: Container(
|
||||||
height: 48,
|
height: 48,
|
||||||
margin: EdgeInsets.only(
|
margin: EdgeInsets.only(
|
||||||
left: 8,
|
left: 8,
|
||||||
right: 8,
|
right: 8,
|
||||||
top: 4 + MediaQuery.of(context).padding.top,
|
top: 4 + MediaQuery.of(context).padding.top,
|
||||||
|
bottom: 4,
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
|
spacing: 8,
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => handleFilterChange(null),
|
onPressed: () => handleFilterChange(null),
|
||||||
icon: Icon(Symbols.explore, color: foregroundColor),
|
icon: Icon(
|
||||||
|
Symbols.explore,
|
||||||
|
color: foregroundColor,
|
||||||
|
fill: currentFilter == null ? 1 : null,
|
||||||
|
),
|
||||||
tooltip: 'explore'.tr(),
|
tooltip: 'explore'.tr(),
|
||||||
isSelected: currentFilter == null,
|
isSelected: currentFilter == null,
|
||||||
|
color: currentFilter == null ? foregroundColor : null,
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => handleFilterChange('subscriptions'),
|
onPressed: () => handleFilterChange('subscriptions'),
|
||||||
icon: Icon(Symbols.subscriptions, color: foregroundColor),
|
icon: Icon(
|
||||||
|
Symbols.subscriptions,
|
||||||
|
color: foregroundColor,
|
||||||
|
fill: currentFilter == 'subscription' ? 1 : null,
|
||||||
|
),
|
||||||
tooltip: 'exploreFilterSubscriptions'.tr(),
|
tooltip: 'exploreFilterSubscriptions'.tr(),
|
||||||
isSelected: currentFilter == 'subscriptions',
|
isSelected: currentFilter == 'subscriptions',
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => handleFilterChange('friends'),
|
onPressed: () => handleFilterChange('friends'),
|
||||||
icon: Icon(Symbols.people, color: foregroundColor),
|
icon: Icon(
|
||||||
|
Symbols.people,
|
||||||
|
color: foregroundColor,
|
||||||
|
fill: currentFilter == 'friends' ? 1 : null,
|
||||||
|
),
|
||||||
tooltip: 'exploreFilterFriends'.tr(),
|
tooltip: 'exploreFilterFriends'.tr(),
|
||||||
isSelected: currentFilter == 'friends',
|
isSelected: currentFilter == 'friends',
|
||||||
),
|
),
|
||||||
@@ -701,17 +727,26 @@ class _DiscoveryActivityItem extends StatelessWidget {
|
|||||||
class _ActivityListView extends HookConsumerWidget {
|
class _ActivityListView extends HookConsumerWidget {
|
||||||
final List<SnTimelineEvent> data;
|
final List<SnTimelineEvent> data;
|
||||||
final bool isWide;
|
final bool isWide;
|
||||||
|
final Widget footer;
|
||||||
|
|
||||||
const _ActivityListView({required this.data, required this.isWide});
|
const _ActivityListView({
|
||||||
|
required this.data,
|
||||||
|
required this.isWide,
|
||||||
|
required this.footer,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final notifier = ref.watch(activityListNotifierProvider.notifier);
|
final notifier = ref.watch(activityListNotifierProvider.notifier);
|
||||||
|
|
||||||
return SliverList.separated(
|
return SliverList.separated(
|
||||||
itemCount: data.length,
|
itemCount: data.length + 1,
|
||||||
separatorBuilder: (_, _) => const Gap(8),
|
separatorBuilder: (_, _) => const Gap(8),
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
if (index == data.length) {
|
||||||
|
return footer;
|
||||||
|
}
|
||||||
|
|
||||||
final item = data[index];
|
final item = data[index];
|
||||||
if (item.data == null) {
|
if (item.data == null) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
|
|||||||
@@ -131,8 +131,10 @@ class FileListView extends HookConsumerWidget {
|
|||||||
FileListMode.unindexed => PaginationWidget(
|
FileListMode.unindexed => PaginationWidget(
|
||||||
provider: unindexedFileListNotifierProvider,
|
provider: unindexedFileListNotifierProvider,
|
||||||
notifier: unindexedFileListNotifierProvider.notifier,
|
notifier: unindexedFileListNotifierProvider.notifier,
|
||||||
|
isRefreshable: false,
|
||||||
|
isSliver: true,
|
||||||
contentBuilder:
|
contentBuilder:
|
||||||
(data) =>
|
(data, footer) =>
|
||||||
data.isEmpty
|
data.isEmpty
|
||||||
? SliverToBoxAdapter(
|
? SliverToBoxAdapter(
|
||||||
child: _buildEmptyUnindexedFilesHint(ref),
|
child: _buildEmptyUnindexedFilesHint(ref),
|
||||||
@@ -145,13 +147,16 @@ class FileListView extends HookConsumerWidget {
|
|||||||
isSelectionMode,
|
isSelectionMode,
|
||||||
selectedFileIds,
|
selectedFileIds,
|
||||||
currentVisibleItems,
|
currentVisibleItems,
|
||||||
|
footer,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
_ => PaginationWidget(
|
_ => PaginationWidget(
|
||||||
provider: indexedCloudFileListNotifierProvider,
|
provider: indexedCloudFileListNotifierProvider,
|
||||||
notifier: indexedCloudFileListNotifierProvider.notifier,
|
notifier: indexedCloudFileListNotifierProvider.notifier,
|
||||||
|
isRefreshable: false,
|
||||||
|
isSliver: true,
|
||||||
contentBuilder:
|
contentBuilder:
|
||||||
(data) =>
|
(data, footer) =>
|
||||||
data.isEmpty
|
data.isEmpty
|
||||||
? SliverToBoxAdapter(
|
? SliverToBoxAdapter(
|
||||||
child: _buildEmptyDirectoryHint(ref, currentPath),
|
child: _buildEmptyDirectoryHint(ref, currentPath),
|
||||||
@@ -165,6 +170,7 @@ class FileListView extends HookConsumerWidget {
|
|||||||
isSelectionMode,
|
isSelectionMode,
|
||||||
selectedFileIds,
|
selectedFileIds,
|
||||||
currentVisibleItems,
|
currentVisibleItems,
|
||||||
|
footer,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
@@ -567,6 +573,7 @@ class FileListView extends HookConsumerWidget {
|
|||||||
ValueNotifier<bool> isSelectionMode,
|
ValueNotifier<bool> isSelectionMode,
|
||||||
ValueNotifier<Set<String>> selectedFileIds,
|
ValueNotifier<Set<String>> selectedFileIds,
|
||||||
ValueNotifier<List<FileListItem>> currentVisibleItems,
|
ValueNotifier<List<FileListItem>> currentVisibleItems,
|
||||||
|
Widget footer,
|
||||||
) {
|
) {
|
||||||
currentVisibleItems.value = items;
|
currentVisibleItems.value = items;
|
||||||
return switch (currentViewMode.value) {
|
return switch (currentViewMode.value) {
|
||||||
@@ -578,7 +585,10 @@ class FileListView extends HookConsumerWidget {
|
|||||||
crossAxisSpacing: 8,
|
crossAxisSpacing: 8,
|
||||||
mainAxisSpacing: 8,
|
mainAxisSpacing: 8,
|
||||||
delegate: SliverChildBuilderDelegate((context, index) {
|
delegate: SliverChildBuilderDelegate((context, index) {
|
||||||
if (index >= items.length) {
|
if (index == items.length) {
|
||||||
|
return footer;
|
||||||
|
}
|
||||||
|
if (index > items.length) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,12 +619,15 @@ class FileListView extends HookConsumerWidget {
|
|||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}, childCount: items.length),
|
}, childCount: items.length + 1),
|
||||||
),
|
),
|
||||||
// ListView mode
|
// ListView mode
|
||||||
_ => SliverList.builder(
|
_ => SliverList.builder(
|
||||||
itemCount: items.length,
|
itemCount: items.length + 1,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
if (index == items.length) {
|
||||||
|
return footer;
|
||||||
|
}
|
||||||
final item = items[index];
|
final item = items[index];
|
||||||
return item.map(
|
return item.map(
|
||||||
file:
|
file:
|
||||||
@@ -1006,6 +1019,7 @@ class FileListView extends HookConsumerWidget {
|
|||||||
ValueNotifier<bool> isSelectionMode,
|
ValueNotifier<bool> isSelectionMode,
|
||||||
ValueNotifier<Set<String>> selectedFileIds,
|
ValueNotifier<Set<String>> selectedFileIds,
|
||||||
ValueNotifier<List<FileListItem>> currentVisibleItems,
|
ValueNotifier<List<FileListItem>> currentVisibleItems,
|
||||||
|
Widget footer,
|
||||||
) {
|
) {
|
||||||
currentVisibleItems.value = items;
|
currentVisibleItems.value = items;
|
||||||
return switch (currentViewMode.value) {
|
return switch (currentViewMode.value) {
|
||||||
@@ -1017,7 +1031,10 @@ class FileListView extends HookConsumerWidget {
|
|||||||
crossAxisSpacing: 12,
|
crossAxisSpacing: 12,
|
||||||
mainAxisSpacing: 12,
|
mainAxisSpacing: 12,
|
||||||
delegate: SliverChildBuilderDelegate((context, index) {
|
delegate: SliverChildBuilderDelegate((context, index) {
|
||||||
if (index >= items.length) {
|
if (index == items.length) {
|
||||||
|
return footer;
|
||||||
|
}
|
||||||
|
if (index > items.length) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1051,12 +1068,15 @@ class FileListView extends HookConsumerWidget {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}, childCount: items.length),
|
}, childCount: items.length + 1),
|
||||||
),
|
),
|
||||||
// ListView mode
|
// ListView mode
|
||||||
_ => SliverList.builder(
|
_ => SliverList.builder(
|
||||||
itemCount: items.length,
|
itemCount: items.length + 1,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
if (index == items.length) {
|
||||||
|
return footer;
|
||||||
|
}
|
||||||
final item = items[index];
|
final item = items[index];
|
||||||
return item.map(
|
return item.map(
|
||||||
file: (fileItem) {
|
file: (fileItem) {
|
||||||
|
|||||||
@@ -1,59 +1,83 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:island/pods/paging.dart';
|
import 'package:island/pods/paging.dart';
|
||||||
|
|
||||||
import 'package:island/widgets/extended_refresh_indicator.dart';
|
import 'package:island/widgets/extended_refresh_indicator.dart';
|
||||||
import 'package:island/widgets/response.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:super_sliver_list/super_sliver_list.dart';
|
||||||
|
import 'package:visibility_detector/visibility_detector.dart';
|
||||||
|
|
||||||
class PaginationList<T> extends HookConsumerWidget {
|
class PaginationList<T> extends HookConsumerWidget {
|
||||||
final ProviderListenable<AsyncValue<List<T>>> provider;
|
final ProviderListenable<AsyncValue<List<T>>> provider;
|
||||||
final Refreshable<PaginationController<T>> notifier;
|
final Refreshable<PaginationController<T>> notifier;
|
||||||
final Widget? Function(BuildContext, int, T) itemBuilder;
|
final Widget? Function(BuildContext, int, T) itemBuilder;
|
||||||
final bool isRefreshable;
|
final bool isRefreshable;
|
||||||
|
final bool isSliver;
|
||||||
|
final bool showDefaultWidgets;
|
||||||
const PaginationList({
|
const PaginationList({
|
||||||
super.key,
|
super.key,
|
||||||
required this.provider,
|
required this.provider,
|
||||||
required this.notifier,
|
required this.notifier,
|
||||||
required this.itemBuilder,
|
required this.itemBuilder,
|
||||||
this.isRefreshable = true,
|
this.isRefreshable = true,
|
||||||
|
this.isSliver = false,
|
||||||
|
this.showDefaultWidgets = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final data = ref.watch(provider);
|
final data = ref.watch(provider);
|
||||||
final noti = ref.watch(notifier);
|
final noti = ref.watch(notifier);
|
||||||
final listView = SuperListView.builder(
|
|
||||||
|
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) {
|
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];
|
final entry = data.valueOrNull?[idx];
|
||||||
if (entry != null) return itemBuilder(context, idx, entry);
|
if (entry != null) return itemBuilder(context, idx, entry);
|
||||||
return null;
|
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,
|
|
||||||
);
|
|
||||||
|
|
||||||
return isRefreshable
|
return isRefreshable
|
||||||
? ExtendedRefreshIndicator(onRefresh: noti.refresh, child: child)
|
? ExtendedRefreshIndicator(onRefresh: noti.refresh, child: listView)
|
||||||
: child;
|
: listView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PaginationWidget<T> extends HookConsumerWidget {
|
class PaginationWidget<T> extends HookConsumerWidget {
|
||||||
final ProviderListenable<AsyncValue<List<T>>> provider;
|
final ProviderListenable<AsyncValue<List<T>>> provider;
|
||||||
final Refreshable<PaginationController<T>> notifier;
|
final Refreshable<PaginationController<T>> notifier;
|
||||||
final Widget Function(List<T>) contentBuilder;
|
final Widget Function(List<T>, Widget) contentBuilder;
|
||||||
final bool isRefreshable;
|
final bool isRefreshable;
|
||||||
final bool isSliver;
|
final bool isSliver;
|
||||||
final bool showDefaultWidgets;
|
final bool showDefaultWidgets;
|
||||||
@@ -72,7 +96,7 @@ class PaginationWidget<T> extends HookConsumerWidget {
|
|||||||
final data = ref.watch(provider);
|
final data = ref.watch(provider);
|
||||||
final noti = ref.watch(notifier);
|
final noti = ref.watch(notifier);
|
||||||
|
|
||||||
if (data.isLoading) {
|
if (data.isLoading && data.valueOrNull?.isEmpty == true) {
|
||||||
final content = ResponseLoadingWidget();
|
final content = ResponseLoadingWidget();
|
||||||
return isSliver ? SliverFillRemaining(child: content) : content;
|
return isSliver ? SliverFillRemaining(child: content) : content;
|
||||||
}
|
}
|
||||||
@@ -85,22 +109,42 @@ class PaginationWidget<T> extends HookConsumerWidget {
|
|||||||
return isSliver ? SliverFillRemaining(child: content) : content;
|
return isSliver ? SliverFillRemaining(child: content) : content;
|
||||||
}
|
}
|
||||||
|
|
||||||
final content = NotificationListener(
|
final footer = PaginationListFooter(noti: noti, data: data);
|
||||||
onNotification: (ScrollNotification scrollInfo) {
|
final content = contentBuilder(data.valueOrNull ?? [], footer);
|
||||||
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 ?? []),
|
|
||||||
);
|
|
||||||
|
|
||||||
return isRefreshable
|
return isRefreshable
|
||||||
? ExtendedRefreshIndicator(onRefresh: noti.refresh, child: content)
|
? ExtendedRefreshIndicator(onRefresh: noti.refresh, child: content)
|
||||||
: 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