Improved attachments

This commit is contained in:
2024-06-01 21:39:28 +08:00
parent a651350104
commit e96b49e3cd
11 changed files with 204 additions and 20 deletions

View File

@ -1,7 +1,9 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:solian/models/attachment.dart';
import 'package:solian/platform.dart';
import 'package:solian/services.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:video_player/video_player.dart';
@ -61,10 +63,33 @@ class _AttachmentItemState extends State<AttachmentItem> {
child: Stack(
fit: StackFit.expand,
children: [
Image.network(
'${ServiceFinder.services['paperclip']}/api/attachments/${widget.item.id}',
fit: widget.fit,
),
if (PlatformInfo.canCacheImage)
CachedNetworkImage(
imageUrl:
'${ServiceFinder.services['paperclip']}/api/attachments/${widget.item.id}',
progressIndicatorBuilder: (context, url, downloadProgress) =>
CircularProgressIndicator(
value: downloadProgress.progress,
),
fit: widget.fit,
)
else
Image.network(
'${ServiceFinder.services['paperclip']}/api/attachments/${widget.item.id}',
fit: widget.fit,
loadingBuilder: (BuildContext context, Widget child,
ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) return child;
return Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!
: null,
),
);
},
),
if (widget.showBadge && widget.badge != null)
Positioned(
right: 12,

View File

@ -390,12 +390,16 @@ class _AttachmentEditingDialogState extends State<AttachmentEditingDialog> {
: null,
isMature: _isMature,
);
Get.find<AttachmentProvider>().clearCache(id: widget.item.id);
setState(() => _isBusy = false);
return Attachment.fromJson(resp.body);
} catch (e) {
context.showErrorDialog(e);
return null;
} finally {
setState(() => _isBusy = false);
return null;
}
}