[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')"
diff --git a/packages/flutter/lib/src/material/floating_action_button.dart b/packages/flutter/lib/src/material/floating_action_button.dart
index 5a43297..48be7dc 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 @@
);
}
- 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 @@
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 a79892b..09aa3fd 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 @@
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 @@
),
);
- 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 @@
);
});
}
+
+Offset _rightEdgeOfFab(WidgetTester tester) {
+ final Finder fab = find.byType(FloatingActionButton);
+ return tester.getRect(fab).centerRight - const Offset(1.0, 0.0);
+}