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 { ...@@ -540,6 +540,7 @@ class SimpleDialogOption extends StatelessWidget {
const SimpleDialogOption({ const SimpleDialogOption({
Key key, Key key,
this.onPressed, this.onPressed,
this.padding,
this.child, this.child,
}) : super(key: key); }) : super(key: key);
...@@ -556,12 +557,17 @@ class SimpleDialogOption extends StatelessWidget { ...@@ -556,12 +557,17 @@ class SimpleDialogOption extends StatelessWidget {
/// Typically a [Text] widget. /// Typically a [Text] widget.
final Widget child; 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return InkWell( return InkWell(
onTap: onPressed, onTap: onPressed,
child: Padding( 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, child: child,
), ),
); );
......
...@@ -11,7 +11,7 @@ import 'package:matcher/matcher.dart'; ...@@ -11,7 +11,7 @@ import 'package:matcher/matcher.dart';
import '../widgets/semantics_tester.dart'; import '../widgets/semantics_tester.dart';
MaterialApp _appWithAlertDialog(WidgetTester tester, AlertDialog dialog, { ThemeData theme }) { MaterialApp _buildAppWithDialog(Widget dialog, { ThemeData theme }) {
return MaterialApp( return MaterialApp(
theme: theme, theme: theme,
home: Material( home: Material(
...@@ -64,7 +64,7 @@ void main() { ...@@ -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.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -80,7 +80,7 @@ void main() { ...@@ -80,7 +80,7 @@ void main() {
backgroundColor: customColor, backgroundColor: customColor,
actions: <Widget>[ ], 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.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -95,7 +95,7 @@ void main() { ...@@ -95,7 +95,7 @@ void main() {
content: Text('Y'), content: Text('Y'),
actions: <Widget>[ ], 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.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -112,7 +112,7 @@ void main() { ...@@ -112,7 +112,7 @@ void main() {
actions: <Widget>[ ], actions: <Widget>[ ],
elevation: customElevation, elevation: customElevation,
); );
await tester.pumpWidget(_appWithAlertDialog(tester, dialog)); await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -129,7 +129,7 @@ void main() { ...@@ -129,7 +129,7 @@ void main() {
titleTextStyle: titleTextStyle, titleTextStyle: titleTextStyle,
actions: <Widget>[ ], actions: <Widget>[ ],
); );
await tester.pumpWidget(_appWithAlertDialog(tester, dialog)); await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -146,7 +146,7 @@ void main() { ...@@ -146,7 +146,7 @@ void main() {
contentTextStyle: contentTextStyle, contentTextStyle: contentTextStyle,
actions: <Widget>[ ], actions: <Widget>[ ],
); );
await tester.pumpWidget(_appWithAlertDialog(tester, dialog)); await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -162,7 +162,7 @@ void main() { ...@@ -162,7 +162,7 @@ void main() {
actions: <Widget>[ ], actions: <Widget>[ ],
shape: customBorder, shape: customBorder,
); );
await tester.pumpWidget(_appWithAlertDialog(tester, dialog)); await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -176,7 +176,7 @@ void main() { ...@@ -176,7 +176,7 @@ void main() {
actions: <Widget>[ ], actions: <Widget>[ ],
shape: null, shape: null,
); );
await tester.pumpWidget(_appWithAlertDialog(tester, dialog)); await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -191,7 +191,7 @@ void main() { ...@@ -191,7 +191,7 @@ void main() {
actions: <Widget>[ ], actions: <Widget>[ ],
shape: customBorder, shape: customBorder,
); );
await tester.pumpWidget(_appWithAlertDialog(tester, dialog)); await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -243,6 +243,32 @@ void main() { ...@@ -243,6 +243,32 @@ void main() {
expect(await result, equals(42)); 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 { testWidgets('Barrier dismissible', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
...@@ -353,7 +379,7 @@ void main() { ...@@ -353,7 +379,7 @@ void main() {
); );
await tester.pumpWidget( await tester.pumpWidget(
_appWithAlertDialog(tester, dialog), _buildAppWithDialog(dialog),
); );
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
...@@ -387,7 +413,7 @@ void main() { ...@@ -387,7 +413,7 @@ void main() {
); );
await tester.pumpWidget( await tester.pumpWidget(
_appWithAlertDialog(tester, dialog), _buildAppWithDialog(dialog),
); );
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
...@@ -429,7 +455,7 @@ void main() { ...@@ -429,7 +455,7 @@ void main() {
); );
await tester.pumpWidget( await tester.pumpWidget(
_appWithAlertDialog(tester, dialog), _buildAppWithDialog(dialog),
); );
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
...@@ -493,7 +519,7 @@ void main() { ...@@ -493,7 +519,7 @@ void main() {
); );
await tester.pumpWidget( await tester.pumpWidget(
_appWithAlertDialog(tester, dialog), _buildAppWithDialog(dialog),
); );
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
...@@ -554,7 +580,7 @@ void main() { ...@@ -554,7 +580,7 @@ void main() {
); );
await tester.pumpWidget( await tester.pumpWidget(
_appWithAlertDialog(tester, dialog), _buildAppWithDialog(dialog),
); );
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
...@@ -954,7 +980,7 @@ void main() { ...@@ -954,7 +980,7 @@ void main() {
), ),
scrollable: true, scrollable: true,
); );
await tester.pumpWidget(_appWithAlertDialog(tester, dialog)); await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -974,7 +1000,7 @@ void main() { ...@@ -974,7 +1000,7 @@ void main() {
), ),
scrollable: true, scrollable: true,
); );
await tester.pumpWidget(_appWithAlertDialog(tester, dialog)); await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -1000,7 +1026,7 @@ void main() { ...@@ -1000,7 +1026,7 @@ void main() {
), ),
scrollable: true, scrollable: true,
); );
await tester.pumpWidget(_appWithAlertDialog(tester, dialog)); await tester.pumpWidget(_buildAppWithDialog(dialog));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); 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