From 2703a2bcde7742496acacf50d4c667c84763f8b0 Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Mon, 28 Nov 2022 07:41:07 +0100 Subject: [PATCH] Fix current day not being decorated when it was disabled for picking. (#115240) Fixes flutter/flutter#113277 --- .../src/material/calendar_date_picker.dart | 14 ++++++++----- .../material/calendar_date_picker_test.dart | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/packages/flutter/lib/src/material/calendar_date_picker.dart b/packages/flutter/lib/src/material/calendar_date_picker.dart index 2e9ac8264a6..567dae2be4c 100644 --- a/packages/flutter/lib/src/material/calendar_date_picker.dart +++ b/packages/flutter/lib/src/material/calendar_date_picker.dart @@ -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( diff --git a/packages/flutter/test/material/calendar_date_picker_test.dart b/packages/flutter/test/material/calendar_date_picker_test.dart index f21300a0438..6c8084d94e9 100644 --- a/packages/flutter/test/material/calendar_date_picker_test.dart +++ b/packages/flutter/test/material/calendar_date_picker_test.dart @@ -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),