diff --git a/packages/core/lib/src/core_widget_factory.dart b/packages/core/lib/src/core_widget_factory.dart index 6e2740e06..08270a422 100644 --- a/packages/core/lib/src/core_widget_factory.dart +++ b/packages/core/lib/src/core_widget_factory.dart @@ -141,7 +141,10 @@ class WidgetFactory { /// Builds [GestureDetector]. Widget? buildGestureDetector( BuildMetadata meta, Widget child, GestureTapCallback onTap) => - GestureDetector(onTap: onTap, child: child); + MouseRegion( + cursor: SystemMouseCursors.click, + child: GestureDetector(onTap: onTap, child: child), + ); /// Builds horizontal scroll view. Widget? buildHorizontalScrollView(BuildMetadata meta, Widget child) => diff --git a/packages/core/lib/src/internal/flattener.dart b/packages/core/lib/src/internal/flattener.dart index e2a560f1b..256b5e106 100644 --- a/packages/core/lib/src/internal/flattener.dart +++ b/packages/core/lib/src/internal/flattener.dart @@ -154,6 +154,8 @@ class Flattener { if (scopedRecognizer != null) _recognizers.add(scopedRecognizer); _spans!.add((context, whitespace) => TextSpan( + mouseCursor: + scopedRecognizer != null ? SystemMouseCursors.click : null, recognizer: scopedRecognizer, style: scopedTsb.build(context).styleWithHeight, text: scopedStrings.toText(whitespace: whitespace), diff --git a/packages/core/pubspec.yaml b/packages/core/pubspec.yaml index 27a045669..0cf76fe29 100644 --- a/packages/core/pubspec.yaml +++ b/packages/core/pubspec.yaml @@ -4,7 +4,7 @@ description: Flutter package for widget tree building from html that focuses on homepage: https://github.com/daohoangson/flutter_widget_from_html/tree/master/packages/core environment: - flutter: ">=2.0.0" + flutter: ">=2.2.0" sdk: ">=2.12.0 <3.0.0" dependencies: diff --git a/packages/core/test/_.dart b/packages/core/test/_.dart index 3bcde3cc3..f5ff27de7 100644 --- a/packages/core/test/_.dart +++ b/packages/core/test/_.dart @@ -566,9 +566,12 @@ class Explainer { // G-M attr.add(widget is GestureDetector ? _widgetChild(widget.child) - : widget is MultiChildRenderObjectWidget - ? (widget is! RichText ? _widgetChildren(widget.children) : '') - : ''); + : widget is MouseRegion + ? _widgetChild(widget.child) + : widget is MultiChildRenderObjectWidget + ? (widget is! RichText ? _widgetChildren(widget.children) : '') + : ''); + // N-T attr.add(widget is ProxyWidget ? _widgetChild(widget.child) diff --git a/packages/core/test/tag_a_test.dart b/packages/core/test/tag_a_test.dart index e13bc1d5b..6c8afa2d3 100644 --- a/packages/core/test/tag_a_test.dart +++ b/packages/core/test/tag_a_test.dart @@ -68,9 +68,9 @@ void main() { final explained = await explain(tester, html); expect( explained, - equals('[GestureDetector:child=' + equals('[MouseRegion:child=[GestureDetector:child=' '[CssBlock:child=[RichText:(#FF123456+u:Foo)]]' - ']'), + ']]'), ); }); @@ -81,8 +81,8 @@ void main() { explained, equals( '[Column:children=' - '[GestureDetector:child=[CssBlock:child=[RichText:(#FF123456+u:Foo)]]],' - '[GestureDetector:child=[CssBlock:child=[RichText:(#FF123456+u:Bar)]]]' + '[MouseRegion:child=[GestureDetector:child=[CssBlock:child=[RichText:(#FF123456+u:Foo)]]]],' + '[MouseRegion:child=[GestureDetector:child=[CssBlock:child=[RichText:(#FF123456+u:Bar)]]]]' ']', ), ); @@ -99,9 +99,9 @@ void main() { final explained = await explain(tester, html); expect( explained, - equals('[CssBlock:child=[GestureDetector:child=' + equals('[CssBlock:child=[MouseRegion:child=[GestureDetector:child=' '[CssBlock:child=[RichText:(#FF123456+u:Foo)]]' - ']]'), + ']]]'), ); }); @@ -112,10 +112,10 @@ void main() { expect( explained, equals( - '[CssBlock:child=[GestureDetector:child=[Column:children=' + '[CssBlock:child=[MouseRegion:child=[GestureDetector:child=[Column:children=' '[CssBlock:child=[RichText:(#FF123456+u:Foo)]],' '[CssBlock:child=[RichText:(#FF123456+u:Bar)]]' - ']]]', + ']]]]', ), ); }); @@ -138,7 +138,10 @@ void main() { expect( explained, equals('[SizedBox:0.0x5.0],' - '[GestureDetector:child=[Padding:(0,5,0,5),child=[CssBlock:child=[RichText:(#FF123456+u:Foo)]]]],' + '[MouseRegion:child=[GestureDetector:child=' + '[Padding:(0,5,0,5),child=' + '[CssBlock:child=[RichText:(#FF123456+u:Foo)]]' + ']]],' '[SizedBox:0.0x5.0]')); }); @@ -152,9 +155,9 @@ void main() { final explained = await explainImg(tester, html); expect( explained, - equals('[GestureDetector:child=' + equals('[MouseRegion:child=[GestureDetector:child=' '[CssSizing:$sizingConstraints,child=[Image:image=NetworkImage("$kImgSrc", scale: 1.0)]]' - ']')); + ']]')); }); testWidgets('renders text + IMG tag both inside', (tester) async { @@ -164,9 +167,9 @@ void main() { explained, equals('[RichText:(:' '(#FF123456+u+onTap:Foo )' - '[GestureDetector:child=' + '[MouseRegion:child=[GestureDetector:child=' '[CssSizing:$sizingConstraints,child=[Image:image=NetworkImage("$kImgSrc", scale: 1.0)]]' - '])]')); + ']])]')); }); testWidgets('renders text outside + IMG tag inside', (tester) async { @@ -175,9 +178,9 @@ void main() { expect( explained, equals('[RichText:(:Foo ' - '[GestureDetector:child=' + '[MouseRegion:child=[GestureDetector:child=' '[CssSizing:$sizingConstraints,child=[Image:image=NetworkImage("$kImgSrc", scale: 1.0)]]' - '])]')); + ']])]')); }); testWidgets('renders IMG tag + text both inside', (tester) async { @@ -186,9 +189,9 @@ void main() { expect( explained, equals('[RichText:(:' - '[GestureDetector:child=' + '[MouseRegion:child=[GestureDetector:child=' '[CssSizing:$sizingConstraints,child=[Image:image=NetworkImage("$kImgSrc", scale: 1.0)]]' - ']' + ']]' '(#FF123456+u+onTap: foo)' ')]')); }); @@ -199,9 +202,9 @@ void main() { expect( explained, equals('[RichText:(:' - '[GestureDetector:child=' + '[MouseRegion:child=[GestureDetector:child=' '[CssSizing:$sizingConstraints,child=[Image:image=NetworkImage("$kImgSrc", scale: 1.0)]]' - ']' + ']]' '(: foo))]')); }); }); diff --git a/packages/enhanced/pubspec.yaml b/packages/enhanced/pubspec.yaml index bbf46b371..7ed7bf75d 100644 --- a/packages/enhanced/pubspec.yaml +++ b/packages/enhanced/pubspec.yaml @@ -4,7 +4,7 @@ description: Flutter package for widget tree building from html that supports hy homepage: https://github.com/daohoangson/flutter_widget_from_html environment: - flutter: ">=2.0.0" + flutter: ">=2.2.0" sdk: ">=2.12.0 <3.0.0" dependencies: