Unverified Commit 19c96282 authored by MH Johnson's avatar MH Johnson Committed by GitHub

[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')"
parent 7cebaac9
...@@ -249,16 +249,6 @@ class _FloatingActionButtonState extends State<FloatingActionButton> { ...@@ -249,16 +249,6 @@ class _FloatingActionButtonState extends State<FloatingActionButton> {
); );
} }
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( result = new RawMaterialButton(
onPressed: widget.onPressed, onPressed: widget.onPressed,
onHighlightChanged: _handleHighlightChanged, onHighlightChanged: _handleHighlightChanged,
...@@ -275,6 +265,15 @@ class _FloatingActionButtonState extends State<FloatingActionButton> { ...@@ -275,6 +265,15 @@ class _FloatingActionButtonState extends State<FloatingActionButton> {
child: result, child: result,
); );
if (widget.tooltip != null) {
result = new MergeSemantics(
child: new Tooltip(
message: widget.tooltip,
child: result,
),
);
}
if (widget.heroTag != null) { if (widget.heroTag != null) {
result = new Hero( result = new Hero(
tag: widget.heroTag, tag: widget.heroTag,
......
...@@ -51,6 +51,47 @@ void main() { ...@@ -51,6 +51,47 @@ void main() {
expect(find.byTooltip('Add'), findsOneWidget); 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 { testWidgets('Floating Action Button tooltip (no child)', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new MaterialApp( new MaterialApp(
...@@ -63,10 +104,10 @@ void main() { ...@@ -63,10 +104,10 @@ void main() {
), ),
); );
expect(find.byType(Text), findsNothing); expect(find.text('Add'), findsNothing);
await tester.longPress(find.byType(FloatingActionButton)); await tester.longPress(find.byType(FloatingActionButton));
await tester.pumpAndSettle(); 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 { testWidgets('FlatActionButton mini size is configurable by ThemeData.materialTapTargetSize', (WidgetTester tester) async {
...@@ -458,3 +499,8 @@ void main() { ...@@ -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);
}
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