🐛 Fix dozens bugs

This commit is contained in:
2025-12-05 01:03:42 +08:00
parent c585522c35
commit a73672925e
8 changed files with 209 additions and 162 deletions

View File

@@ -3,6 +3,7 @@ import 'package:gap/gap.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:island/models/account.dart';
import 'package:island/pods/network.dart';
import 'package:island/pods/paging.dart';
import 'package:island/pods/userinfo.dart';
import 'package:island/screens/account/credits.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/app_scaffold.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:riverpod_paging_utils/riverpod_paging_utils.dart';
import 'package:island/widgets/paging/pagination_list.dart';
import 'package:styled_widget/styled_widget.dart';
part 'leveling.g.dart';
final levelingHistoryNotifierProvider = AsyncNotifierProvider(
LevelingHistoryNotifier.new,
);
@riverpod
class LevelingHistoryNotifier extends _$LevelingHistoryNotifier
with CursorPagingNotifierMixin<SnExperienceRecord> {
static const int _pageSize = 20;
class LevelingHistoryNotifier extends AsyncNotifier<List<SnExperienceRecord>>
with AsyncPaginationController<SnExperienceRecord> {
static const int pageSize = 20;
@override
Future<CursorPagingData<SnExperienceRecord>> build() => fetch(cursor: null);
@override
Future<CursorPagingData<SnExperienceRecord>> fetch({
required String? cursor,
}) async {
Future<List<SnExperienceRecord>> fetch() async {
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(
'/pass/accounts/me/leveling',
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;
final nextCursor = hasMore ? (offset + records.length).toString() : null;
totalCount = int.parse(response.headers.value('X-Total') ?? '0');
return CursorPagingData(
items: records,
hasMore: hasMore,
nextCursor: nextCursor,
);
final List<SnExperienceRecord> records =
response.data
.map((json) => SnExperienceRecord.fromJson(json))
.cast<SnExperienceRecord>()
.toList();
return records;
}
}
@@ -189,52 +181,42 @@ class LevelingScreen extends HookConsumerWidget {
),
),
const SliverGap(8),
PagingHelperSliverView(
PaginationList(
provider: levelingHistoryNotifierProvider,
futureRefreshable: levelingHistoryNotifierProvider.future,
notifierRefreshable: levelingHistoryNotifierProvider.notifier,
contentBuilder:
(data, widgetCount, endItemView) => SliverList.builder(
itemCount: widgetCount,
itemBuilder: (context, index) {
if (index == widgetCount - 1) {
return endItemView;
}
final record = data.items[index];
return ListTile(
title: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(record.reason),
Row(
spacing: 4,
children: [
Text(
record.createdAt.formatRelative(context),
).fontSize(13),
Text('·').fontSize(13).bold(),
Text(
record.createdAt.formatSystem(),
).fontSize(13),
],
).opacity(0.8),
],
),
subtitle: Row(
spacing: 8,
notifier: levelingHistoryNotifierProvider.notifier,
isRefreshable: false,
isSliver: true,
itemBuilder:
(context, idx, record) => ListTile(
title: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(record.reason),
Row(
spacing: 4,
children: [
Text(
'${record.delta > 0 ? '+' : ''}${record.delta} EXP',
),
if (record.bonusMultiplier != 1.0)
Text('x${record.bonusMultiplier}'),
record.createdAt.formatRelative(context),
).fontSize(13),
Text('·').fontSize(13).bold(),
Text(record.createdAt.formatSystem()).fontSize(13),
],
).opacity(0.8),
],
),
subtitle: Row(
spacing: 8,
children: [
Text(
'${record.delta > 0 ? '+' : ''}${record.delta} EXP',
),
minTileHeight: 56,
contentPadding: EdgeInsets.symmetric(horizontal: 4),
);
},
if (record.bonusMultiplier != 1.0)
Text('x${record.bonusMultiplier}'),
],
),
minTileHeight: 56,
contentPadding: EdgeInsets.symmetric(horizontal: 4),
),
),

View File

@@ -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

View File

@@ -573,6 +573,7 @@ class CreatorHubScreen extends HookConsumerWidget {
child: publisherStats.when(
data:
(stats) => SingleChildScrollView(
padding: const EdgeInsets.symmetric(vertical: 24),
child:
currentPublisher.value == null
? ConstrainedBox(
@@ -602,7 +603,7 @@ class CreatorHubScreen extends HookConsumerWidget {
).padding(horizontal: 12),
buildNavigationWidget(true),
],
).padding(vertical: 24)
)
: Column(
spacing: 12,
children: [

View File

@@ -127,11 +127,14 @@ class ExploreScreen extends HookConsumerWidget {
child: Row(
children: [
Row(
spacing: 4,
spacing: 8,
children: [
IconButton(
onPressed: () => handleFilterChange(null),
icon: Icon(Symbols.explore),
icon: Icon(
Symbols.explore,
fill: currentFilter.value == null ? 1 : null,
),
tooltip: 'explore'.tr(),
isSelected: currentFilter.value == null,
color:
@@ -141,7 +144,10 @@ class ExploreScreen extends HookConsumerWidget {
),
IconButton(
onPressed: () => handleFilterChange('subscriptions'),
icon: Icon(Symbols.subscriptions),
icon: Icon(
Symbols.subscriptions,
fill: currentFilter.value == 'subscriptions' ? 1 : null,
),
tooltip: 'exploreFilterSubscriptions'.tr(),
isSelected: currentFilter.value == 'subscriptions',
color:
@@ -151,7 +157,10 @@ class ExploreScreen extends HookConsumerWidget {
),
IconButton(
onPressed: () => handleFilterChange('friends'),
icon: Icon(Symbols.people),
icon: Icon(
Symbols.people,
fill: currentFilter.value == 'friends' ? 1 : null,
),
tooltip: 'exploreFilterFriends'.tr(),
isSelected: currentFilter.value == 'friends',
color:
@@ -312,7 +321,9 @@ class ExploreScreen extends HookConsumerWidget {
// Sliver list cannot provide refresh handled by the pagination list
isRefreshable: false,
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;
return AppBar(
toolbarHeight: 48 + 4,
toolbarHeight: 48,
flexibleSpace: Container(
height: 48,
margin: EdgeInsets.only(
left: 8,
right: 8,
top: 4 + MediaQuery.of(context).padding.top,
bottom: 4,
),
child: Row(
spacing: 8,
children: [
IconButton(
onPressed: () => handleFilterChange(null),
icon: Icon(Symbols.explore, color: foregroundColor),
icon: Icon(
Symbols.explore,
color: foregroundColor,
fill: currentFilter == null ? 1 : null,
),
tooltip: 'explore'.tr(),
isSelected: currentFilter == null,
color: currentFilter == null ? foregroundColor : null,
),
IconButton(
onPressed: () => handleFilterChange('subscriptions'),
icon: Icon(Symbols.subscriptions, color: foregroundColor),
icon: Icon(
Symbols.subscriptions,
color: foregroundColor,
fill: currentFilter == 'subscription' ? 1 : null,
),
tooltip: 'exploreFilterSubscriptions'.tr(),
isSelected: currentFilter == 'subscriptions',
),
IconButton(
onPressed: () => handleFilterChange('friends'),
icon: Icon(Symbols.people, color: foregroundColor),
icon: Icon(
Symbols.people,
color: foregroundColor,
fill: currentFilter == 'friends' ? 1 : null,
),
tooltip: 'exploreFilterFriends'.tr(),
isSelected: currentFilter == 'friends',
),
@@ -701,17 +727,26 @@ class _DiscoveryActivityItem extends StatelessWidget {
class _ActivityListView extends HookConsumerWidget {
final List<SnTimelineEvent> data;
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
Widget build(BuildContext context, WidgetRef ref) {
final notifier = ref.watch(activityListNotifierProvider.notifier);
return SliverList.separated(
itemCount: data.length,
itemCount: data.length + 1,
separatorBuilder: (_, _) => const Gap(8),
itemBuilder: (context, index) {
if (index == data.length) {
return footer;
}
final item = data[index];
if (item.data == null) {
return const SizedBox.shrink();