reorganize and rename widgets
This commit is contained in:
parent
05d25869ef
commit
d5f29dc344
1 changed files with 568 additions and 547 deletions
60
lib/widgets/renderers/message_image.dart
Normal file
60
lib/widgets/renderers/message_image.dart
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:flutter_blurhash/flutter_blurhash.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/helpers/mxc_image.dart";
|
||||
import "package:nexus/models/info/image.dart" as i;
|
||||
import "package:nexus/models/requests/download_media.dart";
|
||||
import "package:nexus/widgets/common/expandable_image.dart";
|
||||
import "package:nexus/widgets/common/loading.dart";
|
||||
|
||||
final class const MessageImage(
|
||||
final Uri url, {
|
||||
final i.ImageInfo? info,
|
||||
required final bool encrypted,
|
||||
final String? filename,
|
||||
super.key,
|
||||
}) extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final request = DownloadMediaRequest(mxc: url, encrypted: encrypted);
|
||||
return ExpandableImage(
|
||||
request,
|
||||
downloadFilename: filename,
|
||||
size: info?.size,
|
||||
child: ClipRRect(
|
||||
borderRadius: .all(.circular(8)),
|
||||
child: AspectRatio(
|
||||
aspectRatio: (info?.width ?? 1) / (info?.height ?? 1),
|
||||
child: Image(
|
||||
image: MxcImage(ref, request),
|
||||
width: info?.width?.toDouble(),
|
||||
fit: .fitWidth,
|
||||
loadingBuilder: (_, child, loadingProgress) =>
|
||||
loadingProgress == null
|
||||
? child
|
||||
: switch (info?.blurHash) {
|
||||
final blurHash? =>
|
||||
info?.width == null || info?.height == null
|
||||
? SizedBox(
|
||||
width: 200,
|
||||
height: 200,
|
||||
child: BlurHash(hash: blurHash),
|
||||
)
|
||||
: SizedBox(
|
||||
width: info!.width!.toDouble(),
|
||||
child: BlurHash(hash: blurHash),
|
||||
),
|
||||
_ => Loading(),
|
||||
},
|
||||
errorBuilder: (context, error, stackTrace) => Center(
|
||||
child: Text(
|
||||
"Image Failed to Load",
|
||||
style: .new(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue