[RaisedButton] Added padding property to RaisedButton.icon (#52393)
This commit is contained in:
parent
8e6e15f915
commit
60b9d15495
@ -202,6 +202,7 @@ class RaisedButton extends MaterialButton {
|
||||
Clip clipBehavior,
|
||||
FocusNode focusNode,
|
||||
bool autofocus,
|
||||
EdgeInsetsGeometry padding,
|
||||
MaterialTapTargetSize materialTapTargetSize,
|
||||
Duration animationDuration,
|
||||
@required Widget icon,
|
||||
@ -278,6 +279,7 @@ class _RaisedButtonWithIcon extends RaisedButton with MaterialButtonWithIconMixi
|
||||
Clip clipBehavior = Clip.none,
|
||||
FocusNode focusNode,
|
||||
bool autofocus = false,
|
||||
EdgeInsetsGeometry padding,
|
||||
MaterialTapTargetSize materialTapTargetSize,
|
||||
Duration animationDuration,
|
||||
@required Widget icon,
|
||||
@ -311,6 +313,7 @@ class _RaisedButtonWithIcon extends RaisedButton with MaterialButtonWithIconMixi
|
||||
clipBehavior: clipBehavior,
|
||||
focusNode: focusNode,
|
||||
autofocus: autofocus,
|
||||
padding: padding,
|
||||
materialTapTargetSize: materialTapTargetSize,
|
||||
animationDuration: animationDuration,
|
||||
child: Row(
|
||||
|
@ -617,6 +617,46 @@ void main() {
|
||||
expect(box.size, equals(const Size(76, 36)));
|
||||
expect(childRect, equals(const Rect.fromLTRB(372.0, 293.0, 428.0, 307.0)));
|
||||
});
|
||||
|
||||
testWidgets('RaisedButton.icon responds to applied padding', (WidgetTester tester) async {
|
||||
const Key buttonKey = Key('test');
|
||||
const Key labelKey = Key('label');
|
||||
await tester.pumpWidget(
|
||||
// When textDirection is set to TextDirection.ltr, the label appears on the
|
||||
// right side of the icon. This is important in determining whether the
|
||||
// horizontal padding is applied correctly later on
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Material(
|
||||
child: Center(
|
||||
child: RaisedButton.icon(
|
||||
icon: const Icon(Icons.add),
|
||||
padding: const EdgeInsets.fromLTRB(16, 5, 10, 12),
|
||||
key: buttonKey,
|
||||
onPressed: () {},
|
||||
label: const Text(
|
||||
'Hello',
|
||||
key: labelKey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Rect paddingRect = tester.getRect(find.byType(Padding));
|
||||
final Rect labelRect = tester.getRect(find.byKey(labelKey));
|
||||
final Rect iconRect = tester.getRect(find.byType(Icon));
|
||||
|
||||
// The right padding should be applied on the right of the label, whereas the
|
||||
// left padding should be applied on the left side of the icon.
|
||||
expect(paddingRect.right, labelRect.right + 10);
|
||||
expect(paddingRect.left, iconRect.left - 16);
|
||||
// Use the taller widget to check the top and bottom padding.
|
||||
final Rect tallerWidget = iconRect.height > labelRect.height ? iconRect : labelRect;
|
||||
expect(paddingRect.top, tallerWidget.top - 5);
|
||||
expect(paddingRect.bottom, tallerWidget.bottom + 12);
|
||||
});
|
||||
}
|
||||
|
||||
TextStyle _iconStyle(WidgetTester tester, IconData icon) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user