Issue
I want to customize DateRangePicker
in flutter, How can I change the following elements?
- Change the
Save
button to image. - Remove the
Switch to input
button. - Change the
header background
color. - Change
day name
color. - Change
background
color. - Change
selected item indicator
color. - Change
selected item text
color. - Change
selected range indicator
color. - 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,
);
},
);
Solution
@Michael Feinstein is right – to elaborate a little bit on what you have to do:
- You need to copy date_range_picker_dialog.dart into your lib folder (you get there by clicking ‘go to implementation’ on showDateRangePicker()
- 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)
- 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 🙂 - 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.
Answered By – Damian K. Bast
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0