Therefore, the only direct impact you have on the colors is by wrapping your CupertinoDatePicker inside a CupertinoTheme and providing a value for textTheme.dateTimePickerTextStyle . Further customisation is not supported as of yet
Since there is no option to change the overlay color from the CupertinoDatePicker widget constructor, you will need to change the overlay color from its source code.
First, we will take an example of CupertinoDatePicker like this:
This represents the implementation of that grey overlay that you see on the screen.
Then, you need to go through the CupertinoPickerDefaultSelectionOverlay source code also, you should find this:
/// default margin and use rounded corners on the left and right side of the
/// rectangular overlay.
/// Default to true and must not be null.
const CupertinoPickerDefaultSelectionOverlay({
super.key,
this.background = CupertinoColors.tertiarySystemFill,
this.capStartEdge = true,
this.capEndEdge = true,
}) : assert(background != null),
assert(capStartEdge != null),
assert(capEndEdge != null);
We want to change the color of that overlay background, so in this line:
2
Answers
Looking at the source code of of
CupertinoDatePicker
, it seems that the colors are not easily changeable.To quote from flutter’s source code:
Therefore, the only direct impact you have on the colors is by wrapping your CupertinoDatePicker inside a
CupertinoTheme
and providing a value fortextTheme.dateTimePickerTextStyle
. Further customisation is not supported as of yetSince there is no option to change the overlay color from the
CupertinoDatePicker
widget constructor, you will need to change the overlay color from its source code.First, we will take an example of
CupertinoDatePicker
like this:And it shows this on the screen:
Going inside its source code, you need to search for those lines:
This represents the implementation of that grey overlay that you see on the screen.
Then, you need to go through the
CupertinoPickerDefaultSelectionOverlay
source code also, you should find this:We want to change the color of that overlay background, so in this line:
this.background = CupertinoColors.tertiarySystemFill,
We will change its value with the
Color
we want, so as an example we will change it like this:and after a hot restart, the result will be:
Notes:
Colors.red
,Colors.green
…, you will need to import the material library onthe top of that file.
const
as I did in the sample ofcode, otherwise, you will get an error.