Unverified Commit d3e1e293 authored by Arthur Denner's avatar Arthur Denner Committed by GitHub

SimpleDialogOption: support custom padding (#50035)

parent 4c1045c0
......@@ -540,6 +540,7 @@ class SimpleDialogOption extends StatelessWidget {
const SimpleDialogOption({
Key key,
this.onPressed,
this.padding,
this.child,
}) : super(key: key);
......@@ -556,12 +557,17 @@ class SimpleDialogOption extends StatelessWidget {
/// Typically a [Text] widget.
final Widget child;
/// The amount of space to surround the [child] with.
///
/// Defaults to EdgeInsets.symmetric(vertical: 8.0, horizontal: 24.0).
final EdgeInsets padding;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onPressed,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 24.0),
padding: padding ?? const EdgeInsets.symmetric(vertical: 8.0, horizontal: 24.0),
child: child,
),
);
......
......@@ -11,7 +11,7 @@ import 'package:matcher/matcher.dart';
import '../widgets/semantics_tester.dart';
MaterialApp _appWithAlertDialog(WidgetTester tester, AlertDialog dialog, { ThemeData theme }) {
MaterialApp _buildAppWithDialog(Widget dialog, { ThemeData theme }) {
return MaterialApp(
theme: theme,
home: Material(
......@@ -64,7 +64,7 @@ void main() {
),
],
);
await tester.pumpWidget(_appWithAlertDialog(tester, dialog));
await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
......@@ -80,7 +80,7 @@ void main() {
backgroundColor: customColor,
actions: <Widget>[ ],
);
await tester.pumpWidget(_appWithAlertDialog(tester, dialog, theme: ThemeData(brightness: Brightness.dark)));
await tester.pumpWidget(_buildAppWithDialog(dialog, theme: ThemeData(brightness: Brightness.dark)));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
......@@ -95,7 +95,7 @@ void main() {
content: Text('Y'),
actions: <Widget>[ ],
);
await tester.pumpWidget(_appWithAlertDialog(tester, dialog, theme: ThemeData(brightness: Brightness.dark)));
await tester.pumpWidget(_buildAppWithDialog(dialog, theme: ThemeData(brightness: Brightness.dark)));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
......@@ -112,7 +112,7 @@ void main() {
actions: <Widget>[ ],
elevation: customElevation,
);
await tester.pumpWidget(_appWithAlertDialog(tester, dialog));
await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
......@@ -129,7 +129,7 @@ void main() {
titleTextStyle: titleTextStyle,
actions: <Widget>[ ],
);
await tester.pumpWidget(_appWithAlertDialog(tester, dialog));
await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
......@@ -146,7 +146,7 @@ void main() {
contentTextStyle: contentTextStyle,
actions: <Widget>[ ],
);
await tester.pumpWidget(_appWithAlertDialog(tester, dialog));
await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
......@@ -162,7 +162,7 @@ void main() {
actions: <Widget>[ ],
shape: customBorder,
);
await tester.pumpWidget(_appWithAlertDialog(tester, dialog));
await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
......@@ -176,7 +176,7 @@ void main() {
actions: <Widget>[ ],
shape: null,
);
await tester.pumpWidget(_appWithAlertDialog(tester, dialog));
await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
......@@ -191,7 +191,7 @@ void main() {
actions: <Widget>[ ],
shape: customBorder,
);
await tester.pumpWidget(_appWithAlertDialog(tester, dialog));
await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
......@@ -243,6 +243,32 @@ void main() {
expect(await result, equals(42));
});
testWidgets('Custom padding on SimpleDialogOption', (WidgetTester tester) async {
const EdgeInsets customPadding = EdgeInsets.fromLTRB(4, 10, 8, 6);
final SimpleDialog dialog = SimpleDialog(
title: const Text('Title'),
children: <Widget>[
SimpleDialogOption(
onPressed: () {},
child: const Text('First option'),
padding: customPadding,
),
],
);
await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
final Rect dialogRect = tester.getRect(find.byType(SimpleDialogOption));
final Rect textRect = tester.getRect(find.text('First option'));
expect(textRect.left, dialogRect.left + customPadding.left);
expect(textRect.top, dialogRect.top + customPadding.top);
expect(textRect.right, dialogRect.right - customPadding.right);
expect(textRect.bottom, dialogRect.bottom - customPadding.bottom);
});
testWidgets('Barrier dismissible', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
......@@ -353,7 +379,7 @@ void main() {
);
await tester.pumpWidget(
_appWithAlertDialog(tester, dialog),
_buildAppWithDialog(dialog),
);
await tester.tap(find.text('X'));
......@@ -387,7 +413,7 @@ void main() {
);
await tester.pumpWidget(
_appWithAlertDialog(tester, dialog),
_buildAppWithDialog(dialog),
);
await tester.tap(find.text('X'));
......@@ -429,7 +455,7 @@ void main() {
);
await tester.pumpWidget(
_appWithAlertDialog(tester, dialog),
_buildAppWithDialog(dialog),
);
await tester.tap(find.text('X'));
......@@ -493,7 +519,7 @@ void main() {
);
await tester.pumpWidget(
_appWithAlertDialog(tester, dialog),
_buildAppWithDialog(dialog),
);
await tester.tap(find.text('X'));
......@@ -554,7 +580,7 @@ void main() {
);
await tester.pumpWidget(
_appWithAlertDialog(tester, dialog),
_buildAppWithDialog(dialog),
);
await tester.tap(find.text('X'));
......@@ -954,7 +980,7 @@ void main() {
),
scrollable: true,
);
await tester.pumpWidget(_appWithAlertDialog(tester, dialog));
await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
......@@ -974,7 +1000,7 @@ void main() {
),
scrollable: true,
);
await tester.pumpWidget(_appWithAlertDialog(tester, dialog));
await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
......@@ -1000,7 +1026,7 @@ void main() {
),
scrollable: true,
);
await tester.pumpWidget(_appWithAlertDialog(tester, dialog));
await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
......
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