[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')"
This commit is contained in:
MH Johnson 2018-08-30 09:59:13 -04:00 committed by GitHub
parent 7cebaac985
commit 19c9628256
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 12 deletions

View file

@ -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(
onPressed: widget.onPressed,
onHighlightChanged: _handleHighlightChanged,
@ -275,6 +265,15 @@ class _FloatingActionButtonState extends State<FloatingActionButton> {
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,

View file

@ -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);
}