Make sure that a DateRangePickerDialog doesn't crash in 0x0 environments (#173754)

This is my attempt to handle
https://github.com/flutter/flutter/issues/6537 for the
DateRangePickerDialog UI control.
This commit is contained in:
Ahmed Mohamed Sameh 2025-10-01 22:01:57 +03:00 committed by GitHub
parent 4f49888a06
commit 7ceee3b074
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -2395,8 +2395,10 @@ class _MonthItemGridDelegate extends SliverGridDelegate {
@override
SliverGridLayout getLayout(SliverConstraints constraints) {
final double tileWidth =
(constraints.crossAxisExtent - 2 * _horizontalPadding) / DateTime.daysPerWeek;
final double tileWidth = math.max(
(constraints.crossAxisExtent - 2 * _horizontalPadding) / DateTime.daysPerWeek,
0.0,
);
return _MonthSliverGridLayout(
crossAxisCount: DateTime.daysPerWeek + 2,
dayChildWidth: tileWidth,

View File

@ -1967,6 +1967,19 @@ void main() {
expect(getDayCount(secondMonthItem), 21);
});
});
testWidgets('DateRangePickerDialog does not crash at zero area', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Center(
child: SizedBox.shrink(
child: DateRangePickerDialog(firstDate: firstDate, lastDate: lastDate),
),
),
),
);
expect(tester.getSize(find.byType(DateRangePickerDialog)), Size.zero);
});
}
class _RestorableDateRangePickerDialogTestWidget extends StatefulWidget {