🐛 Fix attachment loading

This commit is contained in:
LittleSheep 2024-11-13 00:25:02 +08:00
parent 468d1377af
commit b9ad6d4fd0
4 changed files with 39 additions and 4 deletions

View File

@ -49,9 +49,10 @@ class SnAttachmentProvider {
.map((e) => SnAttachment.fromJson(e)) .map((e) => SnAttachment.fromJson(e))
.toList(); .toList();
for (var i = 0; i < out.length; i++) { for (final item in out) {
_cache[pendingFetch[i]] = out[i]; _cache[item.rid] = item;
} }
return rids return rids
.where((rid) => _cache.containsKey(rid)) .where((rid) => _cache.containsKey(rid))
.map((rid) => _cache[rid]!) .map((rid) => _cache[rid]!)

View File

@ -232,7 +232,7 @@ class _ProfileEditScreenState extends State<ProfileEditScreen> {
color: color:
Theme.of(context).colorScheme.surfaceContainerHigh, Theme.of(context).colorScheme.surfaceContainerHigh,
child: _banner != null child: _banner != null
? UniversalImage( ? AutoResizeUniversalImage(
sn.getAttachmentUrl(_banner!), sn.getAttachmentUrl(_banner!),
fit: BoxFit.cover, fit: BoxFit.cover,
) )

View File

@ -210,7 +210,7 @@ class _AccountPublisherEditScreenState
.colorScheme .colorScheme
.surfaceContainerHigh, .surfaceContainerHigh,
child: _banner != null child: _banner != null
? UniversalImage( ? AutoResizeUniversalImage(
sn.getAttachmentUrl(_banner!), sn.getAttachmentUrl(_banner!),
fit: BoxFit.cover, fit: BoxFit.cover,
) )

View File

@ -100,3 +100,37 @@ class UniversalImage extends StatelessWidget {
return NetworkImage(url); return NetworkImage(url);
} }
} }
class AutoResizeUniversalImage extends StatelessWidget {
final String url;
final double? width, height;
final BoxFit? fit;
final bool noProgressIndicator;
final bool noErrorWidget;
const AutoResizeUniversalImage(
this.url, {
super.key,
this.width,
this.height,
this.fit,
this.noProgressIndicator = false,
this.noErrorWidget = false,
});
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
return UniversalImage(
url,
fit: fit,
width: width,
height: height,
noProgressIndicator: noProgressIndicator,
noErrorWidget: noErrorWidget,
cacheHeight: constraints.maxHeight,
cacheWidth: constraints.maxWidth,
);
});
}
}