From d3e1e29375ac0ce14bc4a47fd6a136b484f2a7a0 Mon Sep 17 00:00:00 2001 From: Arthur Denner Date: Wed, 12 Feb 2020 17:58:03 +0100 Subject: [PATCH] SimpleDialogOption: support custom padding (#50035) --- packages/flutter/lib/src/material/dialog.dart | 8 ++- .../flutter/test/material/dialog_test.dart | 62 +++++++++++++------ 2 files changed, 51 insertions(+), 19 deletions(-) diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart index c9e99cf39d..211bf88f11 100644 --- a/packages/flutter/lib/src/material/dialog.dart +++ b/packages/flutter/lib/src/material/dialog.dart @@ -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, ), ); diff --git a/packages/flutter/test/material/dialog_test.dart b/packages/flutter/test/material/dialog_test.dart index 18260300f3..a6eb5d1c18 100644 --- a/packages/flutter/test/material/dialog_test.dart +++ b/packages/flutter/test/material/dialog_test.dart @@ -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: [ ], ); - 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: [ ], ); - 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: [ ], 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: [ ], ); - 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: [ ], ); - 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: [ ], 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: [ ], 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: [ ], 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: [ + 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();