🐛 Fix attachment displaying according the latest server

This commit is contained in:
2024-07-29 17:56:36 +08:00
parent 3ca98fa58c
commit 3db6850d89
6 changed files with 65 additions and 32 deletions

View File

@ -1,5 +1,6 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:get/get.dart';
import 'package:media_kit/media_kit.dart';
import 'package:media_kit_video/media_kit_video.dart';
@ -83,7 +84,9 @@ class _AttachmentItemState extends State<AttachmentItem> {
onPressed: () {
launchUrlString(
ServiceFinder.buildUrl(
'files', '/attachments/${widget.item.id}'),
'files',
'/attachments/${widget.item.id}',
),
);
},
),
@ -125,14 +128,27 @@ class _AttachmentItemImage extends StatelessWidget {
if (PlatformInfo.canCacheImage)
CachedNetworkImage(
fit: fit,
imageUrl:
ServiceFinder.buildUrl('files', '/attachments/${item.id}'),
progressIndicatorBuilder: (context, url, downloadProgress) =>
Center(
child: CircularProgressIndicator(
value: downloadProgress.progress,
),
imageUrl: ServiceFinder.buildUrl(
'files',
'/attachments/${item.id}',
),
progressIndicatorBuilder: (context, url, downloadProgress) {
return Center(
child: CircularProgressIndicator(
value: downloadProgress.progress,
),
);
},
errorWidget: (context, url, error) {
return Material(
color: Theme.of(context).colorScheme.surface,
child: Center(
child: const Icon(Icons.close, size: 32)
.animate(onPlay: (e) => e.repeat(reverse: true))
.fade(duration: 500.ms),
),
);
},
)
else
Image.network(
@ -150,6 +166,16 @@ class _AttachmentItemImage extends StatelessWidget {
),
);
},
errorBuilder: (context, error, stackTrace) {
return Material(
color: Theme.of(context).colorScheme.surface,
child: Center(
child: const Icon(Icons.close, size: 32)
.animate(onPlay: (e) => e.repeat(reverse: true))
.fade(duration: 500.ms),
),
);
},
),
if (showBadge && badge != null)
Positioned(

View File

@ -4,6 +4,7 @@ import 'dart:ui';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:dismissible_page/dismissible_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:get/get.dart';
import 'package:solian/models/attachment.dart';
import 'package:solian/widgets/attachments/attachment_item.dart';
@ -43,7 +44,7 @@ class _AttachmentListState extends State<AttachmentList> {
List<Attachment?> _attachmentsMeta = List.empty();
void getMetadataList() {
void _getMetadataList() {
final AttachmentProvider provider = Get.find();
if (widget.attachmentsId.isEmpty) {
@ -56,8 +57,8 @@ class _AttachmentListState extends State<AttachmentList> {
for (var idx = 0; idx < widget.attachmentsId.length; idx++) {
provider.getMetadata(widget.attachmentsId[idx]).then((resp) {
progress++;
if (resp.body != null) {
_attachmentsMeta[idx] = Attachment.fromJson(resp.body);
if (resp != null) {
_attachmentsMeta[idx] = resp;
}
if (progress == widget.attachmentsId.length) {
calculateAspectRatio();
@ -125,7 +126,7 @@ class _AttachmentListState extends State<AttachmentList> {
@override
void initState() {
super.initState();
getMetadataList();
_getMetadataList();
}
@override
@ -234,19 +235,13 @@ class AttachmentListEntry extends StatelessWidget {
Widget build(BuildContext context) {
if (item == null) {
return Center(
child: Container(
constraints: const BoxConstraints(maxWidth: 280),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.close,
size: 32,
color: Theme.of(context).colorScheme.onSurface,
),
],
),
),
child: Icon(
Icons.close,
size: 32,
color: Theme.of(context).colorScheme.onSurface,
)
.animate(onPlay: (e) => e.repeat(reverse: true))
.fade(duration: 500.ms),
);
}

View File

@ -226,7 +226,7 @@ class _AttachmentPublishPopupState extends State<AttachmentPublishPopup> {
for (var idx = 0; idx < widget.current.length; idx++) {
provider.getMetadata(widget.current[idx]).then((resp) {
progress++;
_attachments[idx] = Attachment.fromJson(resp.body);
_attachments[idx] = resp;
if (progress == widget.current.length) {
setState(() {
_isBusy = false;