From 3ab8451a64ba2fa635f2dd3651fd74a773844fe6 Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Fri, 26 Dec 2025 17:24:02 -0500 Subject: [PATCH] Fix inline widgets --- lib/main.dart | 1 + lib/widgets/chat_page/html/html.dart | 6 ++--- lib/widgets/chat_page/html/mention_chip.dart | 25 ++++++++---------- lib/widgets/chat_page/{ => html}/quoted.dart | 0 lib/widgets/chat_page/html/spoiler_text.dart | 27 +++++++++----------- lib/widgets/chat_page/room_chat.dart | 12 +++++++++ lib/widgets/chat_page/top_widget.dart | 2 +- 7 files changed, 40 insertions(+), 33 deletions(-) rename lib/widgets/chat_page/{ => html}/quoted.dart (100%) diff --git a/lib/main.dart b/lib/main.dart index 0083b82..8cf4365 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -34,6 +34,7 @@ New Value: ${newValue is AsyncData ? newValue.value : newValue} void showError(Object error, [StackTrace? stackTrace]) { if (error.toString().contains("DioException")) return; if (error.toString().contains("UTF-16")) return; + if (error.toString().contains("Invalid image data")) return; debugPrintStack(stackTrace: stackTrace, label: error.toString()); if (navigatorKey.currentContext != null) { diff --git a/lib/widgets/chat_page/html/html.dart b/lib/widgets/chat_page/html/html.dart index 735696e..2ed5b1f 100644 --- a/lib/widgets/chat_page/html/html.dart +++ b/lib/widgets/chat_page/html/html.dart @@ -10,7 +10,7 @@ import "package:nexus/models/image_data.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/code_block.dart"; -import "package:nexus/widgets/chat_page/quoted.dart"; +import "package:nexus/widgets/chat_page/html/quoted.dart"; import "package:nexus/widgets/error_dialog.dart"; class Html extends ConsumerWidget { @@ -23,7 +23,7 @@ class Html extends ConsumerWidget { html, customWidgetBuilder: (element) { if (element.attributes.keys.contains("data-mx-spoiler")) { - return SpoilerText(text: element.text); + return InlineCustomWidget(child: SpoilerText(text: element.text)); } final height = int.tryParse(element.attributes["height"] ?? "") ?? 300; @@ -42,7 +42,7 @@ class Html extends ConsumerWidget { "a" => Uri.tryParse(element.attributes["href"] ?? "")?.host == "matrix.to" - ? MentionChip(element.text) + ? InlineCustomWidget(child: MentionChip(element.text)) : null, "img" => diff --git a/lib/widgets/chat_page/html/mention_chip.dart b/lib/widgets/chat_page/html/mention_chip.dart index 1c53d49..f8fdab1 100644 --- a/lib/widgets/chat_page/html/mention_chip.dart +++ b/lib/widgets/chat_page/html/mention_chip.dart @@ -1,5 +1,4 @@ import "package:flutter/material.dart"; -import "package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart"; import "package:matrix/matrix.dart"; class MentionChip extends StatelessWidget { @@ -7,20 +6,18 @@ class MentionChip extends StatelessWidget { const MentionChip(this.label, {super.key}); @override - Widget build(BuildContext context) => InlineCustomWidget( - child: ActionChip( - label: Text( - label.parseIdentifierIntoParts()?.primaryIdentifier ?? label, - style: TextStyle( - fontWeight: FontWeight.bold, - color: Theme.of(context).colorScheme.onPrimary, - ), + Widget build(BuildContext context) => ActionChip( + label: Text( + label.parseIdentifierIntoParts()?.primaryIdentifier ?? label, + style: TextStyle( + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.onPrimary, ), - backgroundColor: Theme.of(context).colorScheme.primary, - onPressed: () { - // TODO: Open room or join room dialog, or user popover - showAboutDialog(context: context); - }, ), + backgroundColor: Theme.of(context).colorScheme.primary, + onPressed: () { + // TODO: Open room or join room dialog, or user popover + showAboutDialog(context: context); + }, ); } diff --git a/lib/widgets/chat_page/quoted.dart b/lib/widgets/chat_page/html/quoted.dart similarity index 100% rename from lib/widgets/chat_page/quoted.dart rename to lib/widgets/chat_page/html/quoted.dart diff --git a/lib/widgets/chat_page/html/spoiler_text.dart b/lib/widgets/chat_page/html/spoiler_text.dart index 87e1439..9a42bff 100644 --- a/lib/widgets/chat_page/html/spoiler_text.dart +++ b/lib/widgets/chat_page/html/spoiler_text.dart @@ -1,6 +1,5 @@ import "package:flutter/material.dart"; import "package:flutter_hooks/flutter_hooks.dart"; -import "package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart"; class SpoilerText extends HookWidget { final String text; @@ -11,20 +10,18 @@ class SpoilerText extends HookWidget { Widget build(BuildContext context) { final revealed = useState(false); - return InlineCustomWidget( - child: InkWell( - onTap: () => revealed.value = !revealed.value, - child: AnimatedContainer( - duration: const Duration(milliseconds: 100), - padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2), - decoration: BoxDecoration( - color: revealed.value ? Colors.transparent : Colors.blueGrey, - borderRadius: BorderRadius.circular(4), - ), - child: Text( - text, - style: TextStyle(color: revealed.value ? null : Colors.transparent), - ), + return InkWell( + onTap: () => revealed.value = !revealed.value, + child: AnimatedContainer( + duration: const Duration(milliseconds: 100), + padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2), + decoration: BoxDecoration( + color: revealed.value ? Colors.transparent : Colors.blueGrey, + borderRadius: BorderRadius.circular(4), + ), + child: Text( + text, + style: TextStyle(color: revealed.value ? null : Colors.transparent), ), ), ); diff --git a/lib/widgets/chat_page/room_chat.dart b/lib/widgets/chat_page/room_chat.dart index 2d7fdc5..1297b64 100644 --- a/lib/widgets/chat_page/room_chat.dart +++ b/lib/widgets/chat_page/room_chat.dart @@ -262,6 +262,18 @@ class RoomChat extends HookConsumerWidget { groupStatus: groupStatus, alwaysShow: true, ), + errorBuilder: + (context, error, stackTrace) => + Center( + child: Text( + "Image Failed to Load", + style: TextStyle( + color: Theme.of( + context, + ).colorScheme.error, + ), + ), + ), message: message, index: index, headers: room.roomData.client.headers, diff --git a/lib/widgets/chat_page/top_widget.dart b/lib/widgets/chat_page/top_widget.dart index 3f84c3d..733dcc7 100644 --- a/lib/widgets/chat_page/top_widget.dart +++ b/lib/widgets/chat_page/top_widget.dart @@ -3,7 +3,7 @@ import "package:flutter/material.dart"; import "package:flutter_chat_core/flutter_chat_core.dart"; import "package:flutter_chat_ui/flutter_chat_ui.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; -import "package:nexus/widgets/chat_page/quoted.dart"; +import "package:nexus/widgets/chat_page/html/quoted.dart"; class TopWidget extends ConsumerWidget { final Message message;