Skip to content

CalendarDatePicker does not render currentDate as current when disabled #113277

@lclaesen

Description

@lclaesen

The CalendarDatePicker marks the current day (the value of CalendarDatePicker.currentDate) with a BoxDecoration, but unfortunately does so only when that date is selectable, i.e. (1) lies between the startDate and endDate and (2) satisfies the selectableDatePredicate.

There is no reason why it should do so (nor is this documented behavior). It is perfectly normal e.g. that the currentDate is a Sunday, but selection is restricted to week days; in that case, currentDate should appear both as disabled and decorated as being current. Or that selection is possible starting the day after current.

CalendarDatePicker-bug

Steps to Reproduce

Execute flutter run on the code sample

Expected results:
currentDate should be displayed as disabled (not selectable because outside of the calendar range) and still be marked with a BoxDecoration as the current day (as it is displayed when inside the calendar range).

Actual results:
currentDate is not decorated as such.

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CalendarDatePicker(
      firstDate: DateTime(2020, 1, 3),
      lastDate: DateTime(2020, 1, 31),
      currentDate: DateTime(2020, 1, 2), // not between first and last
      initialDate: DateTime(2020, 1, 5),
      onDateChanged: (_) {}
    );
  }
}
Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listf: date/time pickerDate or time picker widgetsf: material designflutter/packages/flutter/material repository.found in release: 3.3Found to occur in 3.3found in release: 3.4Found to occur in 3.4frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions