Search code examples
flutterflutter-date-range-picker

Customize DateRangePicker in flutter


I want to customize DateRangePicker in flutter, How can I change the following elements?

  1. Change the Save button to image.
  2. Remove the Switch to input button.
  3. Change the header background color.
  4. Change day name color.
  5. Change background color.
  6. Change selected item indicator color.
  7. Change selected item text color.
  8. Change selected range indicator color.
  9. Change selected range text color.
showDateRangePicker(
  context: context,
  firstDate: DateTime.now(),
  lastDate: DateTime.now().add(Duration(days: 100)),
  builder: (BuildContext context, Widget child) {
    return Theme(
      data: ThemeData(
        ...
      ),
      child: child,
    );
  },
);

enter image description here


Solution

  • @Michael Feinstein is right - to elaborate a little bit on what you have to do:

    1. You need to copy date_range_picker_dialog.dart into your lib folder (you get there by clicking 'go to implementation' on showDateRangePicker()
    2. You need to copy calendar_date_range_picker.dart (~ line 577 of date_range_picker_dialog.dart is where the actual picker widget is returned as body of the dialog)
    3. You need to make the adjustments you want to do in both files. Your numbers 1-3 are in the dialog, have a look at the class _CalendarRangePickerDialog and change what you need. For your 6-9 look at _buildDayItem in the range picker file and the other 2 are also easy to find :-)
    4. Don't forget to change the import in your copy of date_range_picker_dialog.dart so that you import your copy of the date_range_picker.dart, instead of the original one.

    Now you are all set and good to go.