[Material] Fix Tooltip to respect ambient Directionality (#41629)
* Fix Tooltip Directionality * Add regression test comment for tooltip directionality fix
This commit is contained in:
@@ -286,20 +286,23 @@ class _TooltipState extends State<Tooltip> 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);
|
||||
|
||||
@@ -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<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 {
|
||||
// A Material widget is needed as an ancestor of the Text widget.
|
||||
// It is invalid to have text in a Material application that
|
||||
|
||||
Reference in New Issue
Block a user