'How to change color to opposite theme in cupertino widget?
I have two buttons on the same page that bring up a date picker CupertinoDatePicker. One button just opens the picker, no additional customizations. The second one opens a picker that has a predefined theme locally opposite to the one currently enabled for the app. How can I change the color of the elements of one of them using the theme setting? My code:
CupertinoButton(
onPressed: _showDialog,
child: const Text(
'Select date',
style: TextStyle(
fontSize: 22.0,
),
),
),
void _showDialog() {
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) => Container(
height: 216,
padding: const EdgeInsets.only(top: 6.0),
margin: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
color: CupertinoColors.systemBackground.resolveFrom(context),
child: SafeArea(
top: false,
child: CupertinoDatePicker(
initialDateTime: _date,
mode: CupertinoDatePickerMode.date,
use24hFormat: true,
onDateTimeChanged: (DateTime newDate) {
setState(() => _date = newDate);
},
),
),
),
);
}
Solution 1:[1]
For setState in dialog modal , must wrap first widget in modal into statefullBuilder. You cant setState normally in modal dialog.
See example code:
showModalBottomSheet(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return Container(
height: heightOfModalBottomSheet,
child: RaisedButton(onPressed: () {
setState(() {
heightOfModalBottomSheet += 10;
});
}),
);
});});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Esmaeil Ahmadipour |
