expandable inline images

This commit is contained in:
Henry Hiles 2026-03-30 15:24:26 -04:00
commit 0a6c097c50
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -9,6 +9,7 @@ import "package:nexus/helpers/extensions/get_headers.dart";
import "package:nexus/helpers/extensions/link_to_mention.dart"; import "package:nexus/helpers/extensions/link_to_mention.dart";
import "package:nexus/helpers/extensions/mxc_to_https.dart"; import "package:nexus/helpers/extensions/mxc_to_https.dart";
import "package:nexus/helpers/launch_helper.dart"; import "package:nexus/helpers/launch_helper.dart";
import "package:nexus/widgets/chat_page/expandable_image.dart";
import "package:nexus/widgets/chat_page/html/mention_chip.dart"; import "package:nexus/widgets/chat_page/html/mention_chip.dart";
import "package:nexus/widgets/chat_page/html/spoiler_text.dart"; import "package:nexus/widgets/chat_page/html/spoiler_text.dart";
import "package:nexus/widgets/chat_page/html/code_block.dart"; import "package:nexus/widgets/chat_page/html/code_block.dart";
@ -34,6 +35,16 @@ class Html extends ConsumerWidget {
final height = int.tryParse(element.attributes["height"] ?? "") ?? 300; final height = int.tryParse(element.attributes["height"] ?? "") ?? 300;
final width = int.tryParse(element.attributes["width"] ?? ""); final width = int.tryParse(element.attributes["width"] ?? "");
final src = Uri.tryParse(element.attributes["src"] ?? "")
?.mxcToHttps(
ref.watch(
ClientStateController.provider.select(
(value) => value?.homeserverUrl,
),
) ??
"",
)
.toString();
return switch (element.localName) { return switch (element.localName) {
"code" => "code" =>
@ -56,37 +67,31 @@ class Html extends ConsumerWidget {
: InlineCustomWidget(child: MentionChip(element.text)), : InlineCustomWidget(child: MentionChip(element.text)),
"img" => "img" =>
element.attributes["src"] == null src == null
? SizedBox.shrink() ? SizedBox.shrink()
: InlineCustomWidget( : InlineCustomWidget(
alignment: PlaceholderAlignment.middle, alignment: PlaceholderAlignment.middle,
child: Image( child: ExpandableImage(
image: CachedNetworkImage( src,
Uri.parse(element.attributes["src"]!) child: Image(
.mxcToHttps( image: CachedNetworkImage(
ref.watch( src,
ClientStateController.provider.select( ref.watch(CrossCacheController.provider),
(value) => value?.homeserverUrl, headers: ref.headers,
),
) ??
"",
)
.toString(),
ref.watch(CrossCacheController.provider),
headers: ref.headers,
),
errorBuilder: (_, error, _) => Text(
"Image Failed to Load",
style: TextStyle(
color: Theme.of(context).colorScheme.error,
), ),
errorBuilder: (_, error, _) => Text(
"Image Failed to Load",
style: TextStyle(
color: Theme.of(context).colorScheme.error,
),
),
height: height.toDouble(),
width: width?.toDouble(),
loadingBuilder: (_, child, loadingProgress) =>
loadingProgress == null
? child
: CircularProgressIndicator(),
), ),
height: height.toDouble(),
width: width?.toDouble(),
loadingBuilder: (_, child, loadingProgress) =>
loadingProgress == null
? child
: CircularProgressIndicator(),
), ),
), ),
("del" || ("del" ||