From 19c962825600cc24d8f030cca19d9b4f7d258ab0 Mon Sep 17 00:00:00 2001 From: MH Johnson Date: Thu, 30 Aug 2018 09:59:13 -0400 Subject: [PATCH] [Material] Fix 20051 FAB tooltip touch target (#21084) * [FAB] Updated tooltip touch target. * Remove "new" keyword * [FAB] Updated tooltip touch target. * "long press button edge" * remove new * remove new * put "new" keywords back in * Remove check for childless tooltip * Added regression test - tooltip works on edge of FAB which has no child. Added helper method to find the right edge of a in the tests. * Changed "find.byType(text)" to "find.text('Add')" --- .../src/material/floating_action_button.dart | 19 ++++--- .../material/floating_action_button_test.dart | 50 ++++++++++++++++++- 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/packages/flutter/lib/src/material/floating_action_button.dart b/packages/flutter/lib/src/material/floating_action_button.dart index 5a43297cd2..48be7dc363 100644 --- a/packages/flutter/lib/src/material/floating_action_button.dart +++ b/packages/flutter/lib/src/material/floating_action_button.dart @@ -249,16 +249,6 @@ class _FloatingActionButtonState extends State { ); } - if (widget.tooltip != null) { - final Widget tooltip = new Tooltip( - message: widget.tooltip, - child: result, - ); - // The long-pressable area for the tooltip should always be as big as - // the tooltip even if there is no child. - result = widget.child != null ? tooltip : new SizedBox.expand(child: tooltip); - } - result = new RawMaterialButton( onPressed: widget.onPressed, onHighlightChanged: _handleHighlightChanged, @@ -275,6 +265,15 @@ class _FloatingActionButtonState extends State { child: result, ); + if (widget.tooltip != null) { + result = new MergeSemantics( + child: new Tooltip( + message: widget.tooltip, + child: result, + ), + ); + } + if (widget.heroTag != null) { result = new Hero( tag: widget.heroTag, diff --git a/packages/flutter/test/material/floating_action_button_test.dart b/packages/flutter/test/material/floating_action_button_test.dart index a79892b19f..09aa3fd5f4 100644 --- a/packages/flutter/test/material/floating_action_button_test.dart +++ b/packages/flutter/test/material/floating_action_button_test.dart @@ -51,6 +51,47 @@ void main() { expect(find.byTooltip('Add'), findsOneWidget); }); + // Regression test for: https://github.com/flutter/flutter/pull/21084 + testWidgets('Floating Action Button tooltip (long press button edge)', (WidgetTester tester) async { + await tester.pumpWidget( + new MaterialApp( + home: const Scaffold( + floatingActionButton: FloatingActionButton( + onPressed: null, + tooltip: 'Add', + child: Icon(Icons.add), + ), + ), + ), + ); + + expect(find.text('Add'), findsNothing); + await tester.longPressAt(_rightEdgeOfFab(tester)); + await tester.pumpAndSettle(); + + expect(find.text('Add'), findsOneWidget); + }); + + // Regression test for: https://github.com/flutter/flutter/pull/21084 + testWidgets('Floating Action Button tooltip (long press button edge - no child)', (WidgetTester tester) async { + await tester.pumpWidget( + new MaterialApp( + home: const Scaffold( + floatingActionButton: FloatingActionButton( + onPressed: null, + tooltip: 'Add', + ), + ), + ), + ); + + expect(find.text('Add'), findsNothing); + await tester.longPressAt(_rightEdgeOfFab(tester)); + await tester.pumpAndSettle(); + + expect(find.text('Add'), findsOneWidget); + }); + testWidgets('Floating Action Button tooltip (no child)', (WidgetTester tester) async { await tester.pumpWidget( new MaterialApp( @@ -63,10 +104,10 @@ void main() { ), ); - expect(find.byType(Text), findsNothing); + expect(find.text('Add'), findsNothing); await tester.longPress(find.byType(FloatingActionButton)); await tester.pumpAndSettle(); - expect(find.byType(Text), findsOneWidget); + expect(find.text('Add'), findsOneWidget); }); testWidgets('FlatActionButton mini size is configurable by ThemeData.materialTapTargetSize', (WidgetTester tester) async { @@ -458,3 +499,8 @@ void main() { ); }); } + +Offset _rightEdgeOfFab(WidgetTester tester) { + final Finder fab = find.byType(FloatingActionButton); + return tester.getRect(fab).centerRight - const Offset(1.0, 0.0); +}