Merge branch 'fix_775_room_avatar_flickers' into 'main'

Fix #775: Don't request new thumbnail resolution on every window resize

Closes #775

See merge request famedly/fluffychat!798
This commit is contained in:
Krille Fear 2022-04-03 07:32:12 +00:00
commit a72b54d9ad

View File

@ -1,3 +1,5 @@
import 'dart:ui';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
@ -27,17 +29,7 @@ class ContentBanner extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
final bannerSize =
(mediaQuery.size.width * mediaQuery.devicePixelRatio).toInt();
final onEdit = this.onEdit; final onEdit = this.onEdit;
final src = mxContent?.getThumbnail(
client ?? Matrix.of(context).client,
width: bannerSize,
height: bannerSize,
method: ThumbnailMethod.scale,
animated: true,
);
return Container( return Container(
height: height, height: height,
alignment: Alignment.center, alignment: Alignment.center,
@ -53,12 +45,29 @@ class ContentBanner extends StatelessWidget {
bottom: 0, bottom: 0,
child: Opacity( child: Opacity(
opacity: opacity, opacity: opacity,
child: (!loading && src != null) child: (!loading)
? CachedNetworkImage( ? LayoutBuilder(builder:
(BuildContext context, BoxConstraints constraints) {
// #775 don't request new image resolution on every resize
// by rounding up to the next multiple of stepSize
const stepSize = 300;
final bannerSize =
constraints.maxWidth * window.devicePixelRatio;
final steppedBannerSize =
(bannerSize / stepSize).ceil() * stepSize;
final src = mxContent?.getThumbnail(
client ?? Matrix.of(context).client,
width: steppedBannerSize,
height: steppedBannerSize,
method: ThumbnailMethod.scale,
animated: true,
);
return CachedNetworkImage(
imageUrl: src.toString(), imageUrl: src.toString(),
height: 300, height: 300,
fit: BoxFit.cover, fit: BoxFit.cover,
) );
})
: Icon(defaultIcon, size: 200), : Icon(defaultIcon, size: 200),
), ),
), ),