expandable inline images
This commit is contained in:
parent
08cca4d3d3
commit
0a6c097c50
1 changed files with 31 additions and 26 deletions
|
|
@ -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" ||
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue