Added the materialTapTargetSize to the OutlineButton Constructor (#61086)
This commit is contained in:
@@ -85,6 +85,7 @@ class OutlineButton extends MaterialButton {
|
||||
Clip clipBehavior = Clip.none,
|
||||
FocusNode focusNode,
|
||||
bool autofocus = false,
|
||||
MaterialTapTargetSize materialTapTargetSize,
|
||||
Widget child,
|
||||
}) : assert(highlightElevation == null || highlightElevation >= 0.0),
|
||||
assert(clipBehavior != null),
|
||||
@@ -108,6 +109,7 @@ class OutlineButton extends MaterialButton {
|
||||
shape: shape,
|
||||
clipBehavior: clipBehavior,
|
||||
focusNode: focusNode,
|
||||
materialTapTargetSize: materialTapTargetSize,
|
||||
autofocus: autofocus,
|
||||
child: child,
|
||||
);
|
||||
@@ -143,6 +145,7 @@ class OutlineButton extends MaterialButton {
|
||||
Clip clipBehavior,
|
||||
FocusNode focusNode,
|
||||
bool autofocus,
|
||||
MaterialTapTargetSize materialTapTargetSize,
|
||||
@required Widget icon,
|
||||
@required Widget label,
|
||||
}) = _OutlineButtonWithIcon;
|
||||
@@ -203,6 +206,7 @@ class OutlineButton extends MaterialButton {
|
||||
shape: buttonTheme.getShape(this),
|
||||
clipBehavior: clipBehavior,
|
||||
focusNode: focusNode,
|
||||
materialTapTargetSize: materialTapTargetSize,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
@@ -244,6 +248,7 @@ class _OutlineButtonWithIcon extends OutlineButton with MaterialButtonWithIconMi
|
||||
Clip clipBehavior = Clip.none,
|
||||
FocusNode focusNode,
|
||||
bool autofocus = false,
|
||||
MaterialTapTargetSize materialTapTargetSize,
|
||||
@required Widget icon,
|
||||
@required Widget label,
|
||||
}) : assert(highlightElevation == null || highlightElevation >= 0.0),
|
||||
@@ -274,6 +279,7 @@ class _OutlineButtonWithIcon extends OutlineButton with MaterialButtonWithIconMi
|
||||
clipBehavior: clipBehavior,
|
||||
focusNode: focusNode,
|
||||
autofocus: autofocus,
|
||||
materialTapTargetSize: materialTapTargetSize,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
@@ -311,6 +317,7 @@ class _OutlineButton extends StatefulWidget {
|
||||
this.focusNode,
|
||||
this.autofocus = false,
|
||||
this.child,
|
||||
this.materialTapTargetSize,
|
||||
}) : assert(highlightElevation != null && highlightElevation >= 0.0),
|
||||
assert(highlightedBorderColor != null),
|
||||
assert(clipBehavior != null),
|
||||
@@ -340,6 +347,7 @@ class _OutlineButton extends StatefulWidget {
|
||||
final FocusNode focusNode;
|
||||
final bool autofocus;
|
||||
final Widget child;
|
||||
final MaterialTapTargetSize materialTapTargetSize;
|
||||
|
||||
bool get enabled => onPressed != null || onLongPress != null;
|
||||
|
||||
@@ -489,6 +497,7 @@ class _OutlineButtonState extends State<_OutlineButton> with SingleTickerProvide
|
||||
clipBehavior: widget.clipBehavior,
|
||||
focusNode: widget.focusNode,
|
||||
animationDuration: _kElevationDuration,
|
||||
materialTapTargetSize: widget.materialTapTargetSize,
|
||||
child: widget.child,
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1043,6 +1043,97 @@ void main() {
|
||||
_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 {
|
||||
bool didPressButton = false;
|
||||
bool didLongPressButton = false;
|
||||
|
||||
Reference in New Issue
Block a user