Unverified Commit 913aca22 authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

[Material] Fix Tooltip to respect ambient Directionality (#41629)

* Fix Tooltip Directionality

* Add regression test comment for tooltip directionality fix
parent e7947c3e
...@@ -286,20 +286,23 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin { ...@@ -286,20 +286,23 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
// We create this widget outside of the overlay entry's builder to prevent // 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 // updated values from happening to leak into the overlay when the overlay
// rebuilds. // rebuilds.
final Widget overlay = _TooltipOverlay( final Widget overlay = Directionality(
message: widget.message, textDirection: Directionality.of(context),
height: height, child: _TooltipOverlay(
padding: padding, message: widget.message,
margin: margin, height: height,
decoration: decoration, padding: padding,
textStyle: textStyle, margin: margin,
animation: CurvedAnimation( decoration: decoration,
parent: _controller, textStyle: textStyle,
curve: Curves.fastOutSlowIn, 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); _entry = OverlayEntry(builder: (BuildContext context) => overlay);
Overlay.of(context, debugRequiredFor: widget).insert(_entry); Overlay.of(context, debugRequiredFor: widget).insert(_entry);
......
...@@ -576,6 +576,39 @@ void main() { ...@@ -576,6 +576,39 @@ void main() {
expect(textStyle.decoration, TextDecoration.underline); 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<RenderParagraph>(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<RenderParagraph>(find.text(tooltipText));
expect(tooltipRenderParagraph.textDirection, TextDirection.ltr);
});
testWidgets('Tooltip overlay wrapped with a non-fallback DefaultTextStyle widget', (WidgetTester tester) async { 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. // A Material widget is needed as an ancestor of the Text widget.
// It is invalid to have text in a Material application that // It is invalid to have text in a Material application that
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment