Fix FAB Tooltip semantics label (#16072)
diff --git a/packages/flutter/lib/src/material/floating_action_button.dart b/packages/flutter/lib/src/material/floating_action_button.dart
index ee0a840..103ec9c 100644
--- a/packages/flutter/lib/src/material/floating_action_button.dart
+++ b/packages/flutter/lib/src/material/floating_action_button.dart
@@ -253,6 +253,17 @@
);
}
+ if (widget.tooltip != null) {
+ // The long-pressable area for the tooltip should always be as big as
+ // the tooltip even if there is no child.
+ result = new SizedBox.expand(
+ child: new Tooltip(
+ message: widget.tooltip,
+ child: result,
+ ),
+ );
+ }
+
result = new RawMaterialButton(
onPressed: widget.onPressed,
onHighlightChanged: _handleHighlightChanged,
@@ -267,13 +278,6 @@
child: result,
);
- if (widget.tooltip != null) {
- result = 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 01e22d2..6602a98 100644
--- a/packages/flutter/test/material/floating_action_button_test.dart
+++ b/packages/flutter/test/material/floating_action_button_test.dart
@@ -253,6 +253,40 @@
semantics.dispose();
});
+ testWidgets('Tooltip is used as semantics label', (WidgetTester tester) async {
+ final SemanticsTester semantics = new SemanticsTester(tester);
+
+ await tester.pumpWidget(
+ new MaterialApp(
+ home: new Scaffold(
+ floatingActionButton: new FloatingActionButton(
+ onPressed: () { },
+ tooltip: 'Add Photo',
+ child: const Icon(Icons.add_a_photo),
+ ),
+ ),
+ ),
+ );
+
+ expect(semantics, hasSemantics(new TestSemantics.root(
+ children: <TestSemantics>[
+ new TestSemantics.rootChild(
+ label: 'Add Photo',
+ actions: <SemanticsAction>[
+ SemanticsAction.tap
+ ],
+ flags: <SemanticsFlag>[
+ SemanticsFlag.isButton,
+ SemanticsFlag.hasEnabledState,
+ SemanticsFlag.isEnabled,
+ ],
+ ),
+ ],
+ ), ignoreTransform: true, ignoreId: true, ignoreRect: true));
+
+ semantics.dispose();
+ });
+
group('ComputeNotch', () {
testWidgets('host and guest must intersect', (WidgetTester tester) async {
final ComputeNotch computeNotch = await fetchComputeNotch(tester, const FloatingActionButton(onPressed: null));