Fix current day not being decorated when it was disabled for picking. (#115240)

Fixes flutter/flutter#113277
This commit is contained in:
Jonathan Goyvaerts 2022-11-28 07:41:07 +01:00 committed by GitHub
parent 96d7f9cb13
commit 2703a2bcde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 5 deletions

View File

@ -979,16 +979,20 @@ class _DayPickerState extends State<_DayPicker> {
color: selectedDayBackground,
shape: BoxShape.circle,
);
} else if (isDisabled) {
dayColor = disabledDayColor;
} else if (isToday) {
// The current day gets a different text color and a circle stroke
// The current day gets a different text color (if enabled) and a circle stroke
// border.
dayColor = todayColor;
if (isDisabled) {
dayColor = disabledDayColor;
} else {
dayColor = todayColor;
}
decoration = BoxDecoration(
border: Border.all(color: todayColor),
border: Border.all(color: dayColor),
shape: BoxShape.circle,
);
} else if (isDisabled) {
dayColor = disabledDayColor;
}
Widget dayWidget = Container(

View File

@ -337,6 +337,26 @@ void main() {
);
});
testWidgets('currentDate is highlighted even if it is disabled', (WidgetTester tester) async {
await tester.pumpWidget(calendarDatePicker(
firstDate: DateTime(2016, 1, 3),
lastDate: DateTime(2016, 1, 31),
currentDate: DateTime(2016, 1, 2), // not between first and last
initialDate: DateTime(2016, 1, 5),
));
const Color disabledColor = Color(0x61000000); // default disabled color
expect(
Material.of(tester.element(find.text('2'))),
// The current day should be painted with a circle outline.
paints
..circle(
color: disabledColor,
style: PaintingStyle.stroke,
strokeWidth: 1.0,
),
);
});
testWidgets('Selecting date does not switch picker to year selection', (WidgetTester tester) async {
await tester.pumpWidget(calendarDatePicker(
initialDate: DateTime(2020, DateTime.may, 10),