Skip to content

Commit 2703a2b

Browse files
authored
Fix current day not being decorated when it was disabled for picking. (#115240)
Fixes flutter/flutter#113277
1 parent 96d7f9c commit 2703a2b

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -979,16 +979,20 @@ class _DayPickerState extends State<_DayPicker> {
979979
color: selectedDayBackground,
980980
shape: BoxShape.circle,
981981
);
982-
} else if (isDisabled) {
983-
dayColor = disabledDayColor;
984982
} else if (isToday) {
985-
// The current day gets a different text color and a circle stroke
983+
// The current day gets a different text color (if enabled) and a circle stroke
986984
// border.
987-
dayColor = todayColor;
985+
if (isDisabled) {
986+
dayColor = disabledDayColor;
987+
} else {
988+
dayColor = todayColor;
989+
}
988990
decoration = BoxDecoration(
989-
border: Border.all(color: todayColor),
991+
border: Border.all(color: dayColor),
990992
shape: BoxShape.circle,
991993
);
994+
} else if (isDisabled) {
995+
dayColor = disabledDayColor;
992996
}
993997

994998
Widget dayWidget = Container(

packages/flutter/test/material/calendar_date_picker_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,26 @@ void main() {
337337
);
338338
});
339339

340+
testWidgets('currentDate is highlighted even if it is disabled', (WidgetTester tester) async {
341+
await tester.pumpWidget(calendarDatePicker(
342+
firstDate: DateTime(2016, 1, 3),
343+
lastDate: DateTime(2016, 1, 31),
344+
currentDate: DateTime(2016, 1, 2), // not between first and last
345+
initialDate: DateTime(2016, 1, 5),
346+
));
347+
const Color disabledColor = Color(0x61000000); // default disabled color
348+
expect(
349+
Material.of(tester.element(find.text('2'))),
350+
// The current day should be painted with a circle outline.
351+
paints
352+
..circle(
353+
color: disabledColor,
354+
style: PaintingStyle.stroke,
355+
strokeWidth: 1.0,
356+
),
357+
);
358+
});
359+
340360
testWidgets('Selecting date does not switch picker to year selection', (WidgetTester tester) async {
341361
await tester.pumpWidget(calendarDatePicker(
342362
initialDate: DateTime(2020, DateTime.may, 10),

0 commit comments

Comments
 (0)