From 913aca22b3139ed89fd7d58441f2113bd9bc5051 Mon Sep 17 00:00:00 2001 From: Shi-Hao Hong Date: Thu, 3 Oct 2019 06:41:23 +0800 Subject: [PATCH] [Material] Fix Tooltip to respect ambient Directionality (#41629) * Fix Tooltip Directionality * Add regression test comment for tooltip directionality fix --- .../flutter/lib/src/material/tooltip.dart | 29 ++++++++-------- .../flutter/test/material/tooltip_test.dart | 33 +++++++++++++++++++ 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/packages/flutter/lib/src/material/tooltip.dart b/packages/flutter/lib/src/material/tooltip.dart index 177451f875..54f66a7cec 100644 --- a/packages/flutter/lib/src/material/tooltip.dart +++ b/packages/flutter/lib/src/material/tooltip.dart @@ -286,20 +286,23 @@ class _TooltipState extends State with SingleTickerProviderStateMixin { // We create this widget outside of the overlay entry's builder to prevent // updated values from happening to leak into the overlay when the overlay // rebuilds. - final Widget overlay = _TooltipOverlay( - message: widget.message, - height: height, - padding: padding, - margin: margin, - decoration: decoration, - textStyle: textStyle, - animation: CurvedAnimation( - parent: _controller, - curve: Curves.fastOutSlowIn, + final Widget overlay = Directionality( + textDirection: Directionality.of(context), + child: _TooltipOverlay( + message: widget.message, + height: height, + padding: padding, + margin: margin, + decoration: decoration, + textStyle: textStyle, + animation: CurvedAnimation( + parent: _controller, + curve: Curves.fastOutSlowIn, + ), + target: target, + verticalOffset: verticalOffset, + preferBelow: preferBelow, ), - target: target, - verticalOffset: verticalOffset, - preferBelow: preferBelow, ); _entry = OverlayEntry(builder: (BuildContext context) => overlay); Overlay.of(context, debugRequiredFor: widget).insert(_entry); diff --git a/packages/flutter/test/material/tooltip_test.dart b/packages/flutter/test/material/tooltip_test.dart index 9f68ac3d67..31533ab592 100644 --- a/packages/flutter/test/material/tooltip_test.dart +++ b/packages/flutter/test/material/tooltip_test.dart @@ -576,6 +576,39 @@ void main() { expect(textStyle.decoration, TextDecoration.underline); }); + testWidgets('Tooltip overlay respects ambient Directionality', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/40702. + Widget buildApp(String text, TextDirection textDirection) { + return MaterialApp( + home: Directionality( + textDirection: textDirection, + child: Center( + child: Tooltip( + message: text, + child: Container( + width: 100.0, + height: 100.0, + color: Colors.green[500], + ), + ), + ), + ), + ); + } + + await tester.pumpWidget(buildApp(tooltipText, TextDirection.rtl)); + await tester.longPress(find.byType(Tooltip)); + expect(find.text(tooltipText), findsOneWidget); + RenderParagraph tooltipRenderParagraph = tester.renderObject(find.text(tooltipText)); + expect(tooltipRenderParagraph.textDirection, TextDirection.rtl); + + await tester.pumpWidget(buildApp(tooltipText, TextDirection.ltr)); + await tester.longPress(find.byType(Tooltip)); + expect(find.text(tooltipText), findsOneWidget); + tooltipRenderParagraph = tester.renderObject(find.text(tooltipText)); + expect(tooltipRenderParagraph.textDirection, TextDirection.ltr); + }); + testWidgets('Tooltip overlay wrapped with a non-fallback DefaultTextStyle widget', (WidgetTester tester) async { // A Material widget is needed as an ancestor of the Text widget. // It is invalid to have text in a Material application that