Skip to content

Commit 19d8fbc

Browse files
authored
Made insetPadding configurable for Date Picker Dialog (#155651)
This PR adds following properties to the **DatePickerDialog**: - `insetPadding`
1 parent 5f65bd0 commit 19d8fbc

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

packages/flutter/lib/src/material/date_picker.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ class DatePickerDialog extends StatefulWidget {
334334
this.onDatePickerModeChange,
335335
this.switchToInputEntryModeIcon,
336336
this.switchToCalendarEntryModeIcon,
337+
this.insetPadding = const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0),
337338
}) : initialDate = initialDate == null ? null : DateUtils.dateOnly(initialDate),
338339
firstDate = DateUtils.dateOnly(firstDate),
339340
lastDate = DateUtils.dateOnly(lastDate),
@@ -436,7 +437,6 @@ class DatePickerDialog extends StatefulWidget {
436437
/// Flutter.
437438
final String? restorationId;
438439

439-
440440
/// Called when the [DatePickerDialog] is toggled between
441441
/// [DatePickerEntryMode.calendar],[DatePickerEntryMode.input].
442442
///
@@ -451,6 +451,13 @@ class DatePickerDialog extends StatefulWidget {
451451
/// {@macro flutter.material.date_picker.switchToCalendarEntryModeIcon}
452452
final Icon? switchToCalendarEntryModeIcon;
453453

454+
/// The amount of padding added to [MediaQueryData.viewInsets] on the outside
455+
/// of the dialog. This defines the minimum space between the screen's edges
456+
/// and the dialog.
457+
///
458+
/// Defaults to `EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0)`.
459+
final EdgeInsets insetPadding;
460+
454461
@override
455462
State<DatePickerDialog> createState() => _DatePickerDialogState();
456463
}
@@ -520,9 +527,7 @@ class _DatePickerDialogState extends State<DatePickerDialog> with RestorationMix
520527
}
521528

522529
void _handleDateChanged(DateTime date) {
523-
setState(() {
524-
_selectedDate.value = date;
525-
});
530+
setState(() => _selectedDate.value = date);
526531
}
527532

528533
Size _dialogSize(BuildContext context) {
@@ -725,7 +730,7 @@ class _DatePickerDialogState extends State<DatePickerDialog> with RestorationMix
725730
shape: useMaterial3
726731
? datePickerTheme.shape ?? defaults.shape
727732
: datePickerTheme.shape ?? dialogTheme.shape ?? defaults.shape,
728-
insetPadding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0),
733+
insetPadding: widget.insetPadding,
729734
clipBehavior: Clip.antiAlias,
730735
child: AnimatedContainer(
731736
width: dialogSize.width,

packages/flutter/test/material/date_picker_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,6 +2181,22 @@ void main() {
21812181
});
21822182
});
21832183

2184+
testWidgets('DatePickerDialog with updated insetPadding', (WidgetTester tester) async {
2185+
await tester.pumpWidget(MaterialApp(
2186+
home: Material(
2187+
child: DatePickerDialog(
2188+
initialDate: initialDate,
2189+
firstDate: firstDate,
2190+
lastDate: lastDate,
2191+
insetPadding: const EdgeInsets.fromLTRB(10.0, 20.0, 30.0, 40.0),
2192+
),
2193+
),
2194+
));
2195+
2196+
final Dialog dialog = tester.widget<Dialog>(find.byType(Dialog));
2197+
expect(dialog.insetPadding, const EdgeInsets.fromLTRB(10.0, 20.0, 30.0, 40.0));
2198+
});
2199+
21842200
group('Landscape input-only date picker headers use headlineSmall', () {
21852201
// Regression test for https://github.com/flutter/flutter/issues/122056
21862202

0 commit comments

Comments
 (0)