Unverified Commit c29009b3 authored by Max Weber's avatar Max Weber Committed by GitHub

Added the materialTapTargetSize to the OutlineButton Constructor (#61086)

parent 0268096b
...@@ -85,6 +85,7 @@ class OutlineButton extends MaterialButton { ...@@ -85,6 +85,7 @@ class OutlineButton extends MaterialButton {
Clip clipBehavior = Clip.none, Clip clipBehavior = Clip.none,
FocusNode focusNode, FocusNode focusNode,
bool autofocus = false, bool autofocus = false,
MaterialTapTargetSize materialTapTargetSize,
Widget child, Widget child,
}) : assert(highlightElevation == null || highlightElevation >= 0.0), }) : assert(highlightElevation == null || highlightElevation >= 0.0),
assert(clipBehavior != null), assert(clipBehavior != null),
...@@ -108,6 +109,7 @@ class OutlineButton extends MaterialButton { ...@@ -108,6 +109,7 @@ class OutlineButton extends MaterialButton {
shape: shape, shape: shape,
clipBehavior: clipBehavior, clipBehavior: clipBehavior,
focusNode: focusNode, focusNode: focusNode,
materialTapTargetSize: materialTapTargetSize,
autofocus: autofocus, autofocus: autofocus,
child: child, child: child,
); );
...@@ -143,6 +145,7 @@ class OutlineButton extends MaterialButton { ...@@ -143,6 +145,7 @@ class OutlineButton extends MaterialButton {
Clip clipBehavior, Clip clipBehavior,
FocusNode focusNode, FocusNode focusNode,
bool autofocus, bool autofocus,
MaterialTapTargetSize materialTapTargetSize,
@required Widget icon, @required Widget icon,
@required Widget label, @required Widget label,
}) = _OutlineButtonWithIcon; }) = _OutlineButtonWithIcon;
...@@ -203,6 +206,7 @@ class OutlineButton extends MaterialButton { ...@@ -203,6 +206,7 @@ class OutlineButton extends MaterialButton {
shape: buttonTheme.getShape(this), shape: buttonTheme.getShape(this),
clipBehavior: clipBehavior, clipBehavior: clipBehavior,
focusNode: focusNode, focusNode: focusNode,
materialTapTargetSize: materialTapTargetSize,
child: child, child: child,
); );
} }
...@@ -244,6 +248,7 @@ class _OutlineButtonWithIcon extends OutlineButton with MaterialButtonWithIconMi ...@@ -244,6 +248,7 @@ class _OutlineButtonWithIcon extends OutlineButton with MaterialButtonWithIconMi
Clip clipBehavior = Clip.none, Clip clipBehavior = Clip.none,
FocusNode focusNode, FocusNode focusNode,
bool autofocus = false, bool autofocus = false,
MaterialTapTargetSize materialTapTargetSize,
@required Widget icon, @required Widget icon,
@required Widget label, @required Widget label,
}) : assert(highlightElevation == null || highlightElevation >= 0.0), }) : assert(highlightElevation == null || highlightElevation >= 0.0),
...@@ -274,6 +279,7 @@ class _OutlineButtonWithIcon extends OutlineButton with MaterialButtonWithIconMi ...@@ -274,6 +279,7 @@ class _OutlineButtonWithIcon extends OutlineButton with MaterialButtonWithIconMi
clipBehavior: clipBehavior, clipBehavior: clipBehavior,
focusNode: focusNode, focusNode: focusNode,
autofocus: autofocus, autofocus: autofocus,
materialTapTargetSize: materialTapTargetSize,
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
...@@ -311,6 +317,7 @@ class _OutlineButton extends StatefulWidget { ...@@ -311,6 +317,7 @@ class _OutlineButton extends StatefulWidget {
this.focusNode, this.focusNode,
this.autofocus = false, this.autofocus = false,
this.child, this.child,
this.materialTapTargetSize,
}) : assert(highlightElevation != null && highlightElevation >= 0.0), }) : assert(highlightElevation != null && highlightElevation >= 0.0),
assert(highlightedBorderColor != null), assert(highlightedBorderColor != null),
assert(clipBehavior != null), assert(clipBehavior != null),
...@@ -340,6 +347,7 @@ class _OutlineButton extends StatefulWidget { ...@@ -340,6 +347,7 @@ class _OutlineButton extends StatefulWidget {
final FocusNode focusNode; final FocusNode focusNode;
final bool autofocus; final bool autofocus;
final Widget child; final Widget child;
final MaterialTapTargetSize materialTapTargetSize;
bool get enabled => onPressed != null || onLongPress != null; bool get enabled => onPressed != null || onLongPress != null;
...@@ -489,6 +497,7 @@ class _OutlineButtonState extends State<_OutlineButton> with SingleTickerProvide ...@@ -489,6 +497,7 @@ class _OutlineButtonState extends State<_OutlineButton> with SingleTickerProvide
clipBehavior: widget.clipBehavior, clipBehavior: widget.clipBehavior,
focusNode: widget.focusNode, focusNode: widget.focusNode,
animationDuration: _kElevationDuration, animationDuration: _kElevationDuration,
materialTapTargetSize: widget.materialTapTargetSize,
child: widget.child, child: widget.child,
); );
}, },
......
...@@ -1043,6 +1043,97 @@ void main() { ...@@ -1043,6 +1043,97 @@ void main() {
_checkPhysicalLayer(buttonElement, fillColor.withAlpha(0x00)); _checkPhysicalLayer(buttonElement, fillColor.withAlpha(0x00));
}); });
testWidgets('OutlineButton respects the provided materialTapTargetSize', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Material(
child: Center(
child: OutlineButton(
materialTapTargetSize: MaterialTapTargetSize.padded,
onPressed: () {},
child: const SizedBox(width: 50.0, height: 8.0),
),
),
),
),
);
// Default Width of OutlineButton with MaterialTapTargetSize (88)
expect(tester.getSize(find.byType(OutlineButton)), const Size(88.0, 48.0));
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Material(
child: Center(
child: OutlineButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: () {},
child: const SizedBox(width: 50.0, height: 8.0),
),
),
),
),
);
// Default Width of OutlineButton with MaterialTapTargetSize (88)
expect(tester.getSize(find.byType(OutlineButton)), const Size(88.0, 36.0));
final LocalKey key1 = UniqueKey();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Material(
child: Center(
child: OutlineButton.icon(
key: key1,
materialTapTargetSize: MaterialTapTargetSize.padded,
icon: const Icon(Icons.add_alarm),
label: const SizedBox(width: 50.0, height: 8.0),
onPressed: () { },
),
),
),
),
);
final Size addAlarmIconSize = tester.getSize(find.byIcon(Icons.add_alarm));
// The expected width is the sum of:
// the width of the icon
// the gap between the icon and the label (8)
// the width of the label (50)
// the horizontal padding: start (12), end (16)
expect(tester.getSize(find.byKey(key1)), Size(86 + addAlarmIconSize.width, 48.0));
final LocalKey key2 = UniqueKey();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Material(
child: Center(
child: OutlineButton.icon(
key: key2,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
icon: const Icon(Icons.add),
label: const SizedBox(width: 50.0, height: 8.0),
onPressed: () { },
),
),
),
),
);
// The expected width is the sum of:
// the width of the icon
// the gap between the icon and the label (8)
// the width of the label (50)
// the horizontal padding: start (12), end (16)
final Size addIconSize = tester.getSize(find.byIcon(Icons.add));
expect(tester.getSize(find.byKey(key2)), Size(86 + addIconSize.width, 36.0));
});
testWidgets('OutlineButton onPressed and onLongPress callbacks are distinctly recognized', (WidgetTester tester) async { testWidgets('OutlineButton onPressed and onLongPress callbacks are distinctly recognized', (WidgetTester tester) async {
bool didPressButton = false; bool didPressButton = false;
bool didLongPressButton = false; bool didLongPressButton = false;
......
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