From 0f3919e5394aedfbdc88a257b7fb5722c6afbf22 Mon Sep 17 00:00:00 2001 From: Shi-Hao Hong Date: Mon, 12 Aug 2019 17:24:51 -0400 Subject: [PATCH] Adds DefaultTextStyle ancestor to Tooltip Overlay (#37877) * Add DefaultTextStyle parent widget to Tooltip Overlay * Add test against fallback DefaultTextStyle --- .../flutter/lib/src/material/tooltip.dart | 23 ++++++------ .../flutter/test/material/tooltip_test.dart | 35 ++++++++++++++++++- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/packages/flutter/lib/src/material/tooltip.dart b/packages/flutter/lib/src/material/tooltip.dart index f2d5d1e504..177451f875 100644 --- a/packages/flutter/lib/src/material/tooltip.dart +++ b/packages/flutter/lib/src/material/tooltip.dart @@ -500,16 +500,19 @@ class _TooltipOverlay extends StatelessWidget { opacity: animation, child: ConstrainedBox( constraints: BoxConstraints(minHeight: height), - child: Container( - decoration: decoration, - padding: padding, - margin: margin, - child: Center( - widthFactor: 1.0, - heightFactor: 1.0, - child: Text( - message, - style: textStyle, + child: DefaultTextStyle( + style: Theme.of(context).textTheme.body1, + child: Container( + decoration: decoration, + padding: padding, + margin: margin, + child: Center( + widthFactor: 1.0, + heightFactor: 1.0, + child: Text( + message, + style: textStyle, + ), ), ), ), diff --git a/packages/flutter/test/material/tooltip_test.dart b/packages/flutter/test/material/tooltip_test.dart index 7e2332e349..e88d6d9c24 100644 --- a/packages/flutter/test/material/tooltip_test.dart +++ b/packages/flutter/test/material/tooltip_test.dart @@ -557,7 +557,7 @@ void main() { key: key, textStyle: const TextStyle( color: Colors.orange, - decoration: TextDecoration.underline + decoration: TextDecoration.underline, ), message: tooltipText, child: Container( @@ -576,6 +576,39 @@ void main() { expect(textStyle.decoration, TextDecoration.underline); }); + 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 + // does not have a Material ancestor. + final GlobalKey key = GlobalKey(); + await tester.pumpWidget(MaterialApp( + home: Tooltip( + key: key, + message: tooltipText, + child: Container( + width: 100.0, + height: 100.0, + color: Colors.green[500], + ), + ), + )); + (key.currentState as dynamic).ensureTooltipVisible(); // Before using "as dynamic" in your code, see note at the top of the file. + await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0) + + final TextStyle textStyle = tester.widget( + find.ancestor( + of: find.text(tooltipText), + matching: find.byType(DefaultTextStyle), + ).first, + ).style; + + // The default fallback text style results in a text with a + // double underline of Color(0xffffff00). + expect(textStyle.decoration, isNot(TextDecoration.underline)); + expect(textStyle.decorationColor, isNot(const Color(0xffffff00))); + expect(textStyle.decorationStyle, isNot(TextDecorationStyle.double)); + }); + testWidgets('Does tooltip end up with the right default size, shape, and color', (WidgetTester tester) async { final GlobalKey key = GlobalKey(); await tester.pumpWidget(