Delete sticker

This commit is contained in:
LittleSheep 2025-02-23 14:15:32 +08:00
parent eb29f76b9a
commit 537f404fe0

View File

@ -39,6 +39,29 @@ class _StickerPackScreenState extends State<StickerPackScreen> {
bool _isBusy = false; bool _isBusy = false;
Future<void> _deleteSticker(SnSticker sticker) async {
final confirm = await context.showConfirmDialog(
'stickersDelete'.tr(args: [sticker.name]),
'stickersDeleteDescription'.tr(),
);
if (!confirm) return;
if (!mounted) return;
try {
setState(() => _isBusy = true);
final sn = context.read<SnNetworkProvider>();
await sn.client.delete('/cgi/uc/stickers/${sticker.id}');
if (!mounted) return;
context.showSnackbar('stickersDeleted'.tr());
_fetchPack();
} catch (err) {
if (!mounted) return;
context.showErrorDialog(err);
} finally {
setState(() => _isBusy = false);
}
}
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -92,18 +115,23 @@ class _StickerPackScreenState extends State<StickerPackScreen> {
crossAxisSpacing: 8, crossAxisSpacing: 8,
children: _pack!.stickers! children: _pack!.stickers!
.map( .map(
(ele) => ClipRRect( (ele) => GestureDetector(
borderRadius: BorderRadius.circular(8), child: ClipRRect(
child: Container( borderRadius: BorderRadius.circular(8),
color: Theme.of(context) child: Container(
.colorScheme color: Theme.of(context)
.surfaceContainerHigh, .colorScheme
child: AttachmentItem( .surfaceContainerHigh,
data: ele.attachment, child: AttachmentItem(
heroTag: 'sticker-pack-${ele.attachment.rid}', data: ele.attachment,
fit: BoxFit.contain, heroTag: 'sticker-pack-${ele.attachment.rid}',
fit: BoxFit.contain,
),
), ),
), ),
onTap: () {
_deleteSticker(ele);
},
), ),
) )
.toList(), .toList(),