🐛 Fix serval bugs

This commit is contained in:
2025-12-06 20:53:24 +08:00
parent 39ed5393ab
commit 51853698b9
2 changed files with 159 additions and 183 deletions

View File

@@ -127,102 +127,88 @@ class MarketplaceStickerPackDetailScreen extends HookConsumerWidget {
// Stickers grid // Stickers grid
Expanded( Expanded(
child: packContent.when( child: packContent.when(
data: data: (stickers) => RefreshIndicator(
(stickers) => RefreshIndicator( onRefresh: () => ref.refresh(
onRefresh: marketplaceStickerPackContentProvider(packId: id).future,
() => ref.refresh( ),
marketplaceStickerPackContentProvider( child: GridView.builder(
packId: id, padding: const EdgeInsets.symmetric(
).future, horizontal: 24,
), vertical: 20,
child: GridView.builder( ),
padding: const EdgeInsets.symmetric( gridDelegate:
horizontal: 24, const SliverGridDelegateWithMaxCrossAxisExtent(
vertical: 20, maxCrossAxisExtent: 96,
mainAxisSpacing: 12,
crossAxisSpacing: 12,
), ),
gridDelegate: itemCount: stickers.length,
const SliverGridDelegateWithMaxCrossAxisExtent( itemBuilder: (context, index) {
maxCrossAxisExtent: 96, final sticker = stickers[index];
mainAxisSpacing: 12, return Tooltip(
crossAxisSpacing: 12, message: ':${p?.prefix ?? ''}${sticker.slug}:',
), child: ClipRRect(
itemCount: stickers.length, borderRadius: const BorderRadius.all(
itemBuilder: (context, index) { Radius.circular(8),
final sticker = stickers[index]; ),
return Tooltip( child: Container(
message: ':${p?.prefix ?? ''}${sticker.slug}:', decoration: BoxDecoration(
child: ClipRRect( color: Theme.of(
context,
).colorScheme.surfaceContainer,
borderRadius: const BorderRadius.all( borderRadius: const BorderRadius.all(
Radius.circular(8), Radius.circular(8),
), ),
child: Container( ),
decoration: BoxDecoration( child: AspectRatio(
color: aspectRatio: 1,
Theme.of( child: CloudImageWidget(
context, fileId: sticker.image.id,
).colorScheme.surfaceContainer, fit: BoxFit.contain,
borderRadius: const BorderRadius.all(
Radius.circular(8),
),
),
child: AspectRatio(
aspectRatio: 1,
child: CloudImageWidget(
fileId: sticker.image.id,
fit: BoxFit.contain,
),
),
), ),
), ),
); ),
}, ),
), );
), },
error: ),
(err, _) => ),
Text( error: (err, _) => Text(
'Error: $err', 'Error: $err',
).textAlignment(TextAlign.center).center(), ).textAlignment(TextAlign.center).center(),
loading: () => const CircularProgressIndicator().center(), loading: () => const CircularProgressIndicator().center(),
), ),
), ),
Padding( Padding(
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 8), padding: EdgeInsets.symmetric(horizontal: 24, vertical: 8),
child: owned.when( child: owned.when(
data: data: (isOwned) => FilledButton.icon(
(isOwned) => FilledButton.icon( onPressed: isOwned
onPressed: ? removePackFromMyCollection
isOwned : addPackToMyCollection,
? removePackFromMyCollection icon: Icon(
: addPackToMyCollection, isOwned ? Symbols.remove_circle : Symbols.add_circle,
icon: Icon( ),
isOwned ? Symbols.remove_circle : Symbols.add_circle, label: Text(isOwned ? 'removePack'.tr() : 'addPack'.tr()),
), ),
label: Text( loading: () => const SizedBox(
isOwned ? 'removePack'.tr() : 'addPack'.tr(), height: 32,
), width: 32,
), child: CircularProgressIndicator(strokeWidth: 2),
loading: ).center(),
() => const SizedBox( error: (_, _) => OutlinedButton.icon(
height: 32, onPressed: addPackToMyCollection,
width: 32, icon: const Icon(Symbols.add_circle),
child: CircularProgressIndicator(strokeWidth: 2), label: Text('addPack').tr(),
), ),
error:
(_, _) => OutlinedButton.icon(
onPressed: addPackToMyCollection,
icon: const Icon(Symbols.add_circle),
label: Text('addPack').tr(),
),
), ),
), ),
Gap(MediaQuery.of(context).padding.bottom + 16), Gap(MediaQuery.of(context).padding.bottom + 16),
], ],
); );
}, },
error: error: (err, _) =>
(err, _) => Text('Error: $err').textAlignment(TextAlign.center).center(),
Text('Error: $err').textAlignment(TextAlign.center).center(),
loading: () => const CircularProgressIndicator().center(), loading: () => const CircularProgressIndicator().center(),
), ),
); );

View File

@@ -60,11 +60,10 @@ class MarketplaceStickerPacksNotifier extends AsyncNotifier<List<SnStickerPack>>
); );
totalCount = int.parse(response.headers.value('X-Total') ?? '0'); totalCount = int.parse(response.headers.value('X-Total') ?? '0');
final stickers = final stickers = response.data
response.data .map((e) => SnStickerPack.fromJson(e))
.map((e) => SnStickerPack.fromJson(e)) .cast<SnStickerPack>()
.cast<SnStickerPack>() .toList();
.toList();
return stickers; return stickers;
} }
@@ -112,14 +111,12 @@ class MarketplaceStickersScreen extends HookConsumerWidget {
onPressed: () { onPressed: () {
query.value = query.value.copyWith(byUsage: !query.value.byUsage); query.value = query.value.copyWith(byUsage: !query.value.byUsage);
}, },
icon: icon: query.value.byUsage
query.value.byUsage ? const Icon(Symbols.local_fire_department)
? const Icon(Symbols.local_fire_department) : const Icon(Symbols.access_time),
: const Icon(Symbols.access_time), tooltip: query.value.byUsage
tooltip: ? 'orderByPopularity'.tr()
query.value.byUsage : 'orderByReleaseDate'.tr(),
? 'orderByPopularity'.tr()
: 'orderByReleaseDate'.tr(),
), ),
const Gap(8), const Gap(8),
], ],
@@ -137,8 +134,8 @@ class MarketplaceStickersScreen extends HookConsumerWidget {
padding: WidgetStateProperty.all( padding: WidgetStateProperty.all(
const EdgeInsets.symmetric(horizontal: 24), const EdgeInsets.symmetric(horizontal: 24),
), ),
onTapOutside: onTapOutside: (_) =>
(_) => FocusManager.instance.primaryFocus?.unfocus(), FocusManager.instance.primaryFocus?.unfocus(),
trailing: [ trailing: [
if (query.value.query != null && query.value.query!.isNotEmpty) if (query.value.query != null && query.value.query!.isNotEmpty)
IconButton( IconButton(
@@ -171,26 +168,53 @@ class MarketplaceStickersScreen extends HookConsumerWidget {
padding: EdgeInsets.only(top: 8), padding: EdgeInsets.only(top: 8),
provider: marketplaceStickerPacksNotifierProvider, provider: marketplaceStickerPacksNotifierProvider,
notifier: marketplaceStickerPacksNotifierProvider.notifier, notifier: marketplaceStickerPacksNotifierProvider.notifier,
itemBuilder: itemBuilder: (context, idx, pack) => Card(
(context, idx, pack) => Card( margin: EdgeInsets.symmetric(horizontal: 12, vertical: 4),
margin: EdgeInsets.symmetric(horizontal: 12, vertical: 4), child: Column(
child: Column( children: [
children: [ if (pack.stickers.isNotEmpty)
Container( Container(
color: color: Theme.of(context).colorScheme.secondaryContainer,
Theme.of(context).colorScheme.secondaryContainer, child: Padding(
child: Padding( padding: const EdgeInsets.symmetric(
padding: const EdgeInsets.symmetric( horizontal: 20,
horizontal: 20, vertical: 20,
vertical: 20, ),
), child: Column(
child: Column( mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center, children: [
children: [ Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(
math.min(pack.stickers.length, 4),
(index) => Padding(
padding: EdgeInsets.only(
right: index < 3 ? 8 : 0,
),
child: Container(
constraints: const BoxConstraints(
maxWidth: 80,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Theme.of(
context,
).colorScheme.tertiaryContainer,
),
child: CloudImageWidget(
file: pack.stickers[index].image,
),
).clipRRect(all: 8),
),
),
),
if (pack.stickers.length > 4)
const SizedBox(height: 8),
if (pack.stickers.length > 4)
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: List.generate( children: List.generate(
math.min(pack.stickers.length, 4), math.min(pack.stickers.length - 4, 4),
(index) => Padding( (index) => Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
right: index < 3 ? 8 : 0, right: index < 3 ? 8 : 0,
@@ -203,89 +227,55 @@ class MarketplaceStickersScreen extends HookConsumerWidget {
borderRadius: BorderRadius.circular( borderRadius: BorderRadius.circular(
8, 8,
), ),
color: color: Theme.of(
Theme.of( context,
context, ).colorScheme.tertiaryContainer,
).colorScheme.tertiaryContainer,
), ),
child: CloudImageWidget( child: CloudImageWidget(
file: pack.stickers[index].image, file: pack.stickers[index + 4].image,
), ),
).clipRRect(all: 8), ).clipRRect(all: 8),
), ),
), ),
), ),
if (pack.stickers.length > 4) ],
const SizedBox(height: 8),
if (pack.stickers.length > 4)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(
math.min(pack.stickers.length - 4, 4),
(index) => Padding(
padding: EdgeInsets.only(
right: index < 3 ? 8 : 0,
),
child: Container(
constraints: const BoxConstraints(
maxWidth: 80,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
8,
),
color:
Theme.of(
context,
).colorScheme.tertiaryContainer,
),
child: CloudImageWidget(
file:
pack.stickers[index + 4].image,
),
).clipRRect(all: 8),
),
),
),
],
),
), ),
).clipRRect(topLeft: 8, topRight: 8),
ListTile(
leading: Container(
decoration: BoxDecoration(
color:
Theme.of(
context,
).colorScheme.tertiaryContainer,
borderRadius: const BorderRadius.all(
Radius.circular(8),
),
),
child: CloudImageWidget(
file: pack.icon ?? pack.stickers.first.image,
),
).width(40).height(40).clipRRect(all: 8),
shape: RoundedRectangleBorder(
borderRadius: const BorderRadius.all(
Radius.circular(8),
),
),
title: Text(pack.name),
subtitle: Text(pack.description),
trailing: const Icon(Symbols.chevron_right),
onTap: () {
// Navigate to user-facing sticker pack detail page.
// Adjust the route name/parameters if your app uses different ones.
context.pushNamed(
'stickerPackDetail',
pathParameters: {'packId': pack.id},
);
},
), ),
], ).clipRRect(topLeft: 8, topRight: 8),
ListTile(
leading: Container(
decoration: BoxDecoration(
color: Theme.of(
context,
).colorScheme.tertiaryContainer,
borderRadius: const BorderRadius.all(
Radius.circular(8),
),
),
child: CloudImageWidget(
file: pack.icon ?? pack.stickers.firstOrNull?.image,
),
).width(40).height(40).clipRRect(all: 8),
shape: RoundedRectangleBorder(
borderRadius: const BorderRadius.all(
Radius.circular(8),
),
),
title: Text(pack.name),
subtitle: Text(pack.description),
trailing: const Icon(Symbols.chevron_right),
onTap: () {
// Navigate to user-facing sticker pack detail page.
// Adjust the route name/parameters if your app uses different ones.
context.pushNamed(
'stickerPackDetail',
pathParameters: {'packId': pack.id},
);
},
), ),
), ],
),
),
), ),
), ),
], ],