From ed761d6071273a3091dfcdb17e341dcccf99b74e Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Tue, 22 Sep 2026 20:40:55 -0400 Subject: [PATCH] gate selectable text behind mouse connected --- lib/widgets/html/html.dart | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/widgets/html/html.dart b/lib/widgets/html/html.dart index f10aad4..6cb60b2 100644 --- a/lib/widgets/html/html.dart +++ b/lib/widgets/html/html.dart @@ -1,4 +1,5 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart"; +import "package:flutter/rendering.dart"; import "package:material_ui/material_ui.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; import "package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart"; @@ -18,10 +19,9 @@ class const Html( super.key, }) extends ConsumerWidget { @override - Widget build(BuildContext context, WidgetRef ref) => SelectableRegion( - selectionControls: materialTextSelectionControls, + Widget build(BuildContext context, WidgetRef ref) { // needed until https://github.com/daohoangson/flutter_widget_from_html/issues/1618 is resolved - child: MaterialUiCompatibilityBridge( + final htmlWidget = MaterialUiCompatibilityBridge( child: HtmlWidget( html, buildAsync: false, @@ -146,6 +146,13 @@ class const Html( onTapUrl: (url) => ref.watch(LaunchHelper.provider).launchUrl(.parse(url)), ), - ), - ); + ); + + return RendererBinding.instance.mouseTracker.mouseIsConnected + ? SelectableRegion( + selectionControls: materialTextSelectionControls, + child: htmlWidget, + ) + : htmlWidget; + } }