From 6a080aa950f076d13690bfc3f6027ef945a0b23b Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Tue, 3 Apr 2018 08:14:06 -0700 Subject: [PATCH] Fix ExtendedFloatingActionButton width (#16168) --- .../lib/src/material/floating_action_button.dart | 11 +++++------ .../test/material/floating_action_button_test.dart | 12 +++++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/flutter/lib/src/material/floating_action_button.dart b/packages/flutter/lib/src/material/floating_action_button.dart index 103ec9c5b9..7a305f78ad 100644 --- a/packages/flutter/lib/src/material/floating_action_button.dart +++ b/packages/flutter/lib/src/material/floating_action_button.dart @@ -254,14 +254,13 @@ 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 = new SizedBox.expand( - child: new Tooltip( - message: widget.tooltip, - child: result, - ), - ); + result = widget.child != null ? tooltip : new SizedBox.expand(child: tooltip); } result = new RawMaterialButton( diff --git a/packages/flutter/test/material/floating_action_button_test.dart b/packages/flutter/test/material/floating_action_button_test.dart index 6602a9839c..44e26c5112 100644 --- a/packages/flutter/test/material/floating_action_button_test.dart +++ b/packages/flutter/test/material/floating_action_button_test.dart @@ -91,7 +91,10 @@ void main() { new MaterialApp( home: new Scaffold( floatingActionButton: new FloatingActionButton.extended( - label: const Text('label'), + label: const SizedBox( + width: 100.0, + child: const Text('label'), + ), icon: const Icon(Icons.android), onPressed: null, ), @@ -107,6 +110,7 @@ void main() { // Verify that the widget's height is 48 and that its internal /// horizontal layout is: 16 icon 8 label 20 expect(tester.getSize(fabFinder).height, 48.0); + final double fabLeft = tester.getTopLeft(fabFinder).dx; final double fabRight = tester.getTopRight(fabFinder).dx; final double iconLeft = tester.getTopLeft(find.byType(Icon)).dx; @@ -116,6 +120,12 @@ void main() { expect(iconLeft - fabLeft, 16.0); expect(labelLeft - iconRight, 8.0); expect(fabRight - labelRight, 20.0); + + // The overall width of the button is: + // 168 = 16 + 24(icon) + 8 + 100(label) + 20 + expect(tester.getSize(find.byType(Icon)).width, 24.0); + expect(tester.getSize(find.text('label')).width, 100.0); + expect(tester.getSize(fabFinder).width, 168); }); testWidgets('Floating Action Button heroTag', (WidgetTester tester) async {