我的应用程序中的CupertinoDatePicker使用以下代码来选择日期和时间:
formatColumn(
widget: Consumer<MainCalendarProvider>(
builder: (_, mcProvider, __) => SizedBox(
height: sizes.height(context) / 3.5,
child: CupertinoDatePicker(
initialDateTime: result['dateRevision'],
minimumDate: result['dateRevision'],
use24hFormat: true,
onDateTimeChanged: (dateChange) {
mcProvider.setSelectedDateFromCupertinoDatePicker( dateChange, );},
),
),
),
title: 'Date Activity'),
一切正常,直到我在应用程序中添加了功能暗模式。在暗模式下,文本颜色CupertinoDatePicker仍为黑色,我想将其更改为白色。 在CupertinoDatePicker中,仅具有backgroundcolor属性。我已经尝试将其更改为红色,蓝色,绿色等,但文本仍为黑色。
我该如何更改?
谢谢。
答案 0 :(得分:2)
我不知道您是否在Theme
中缺少某些样式,但是one of these solutions可能会成功!
答案 1 :(得分:1)
我想CupertinoTheme
不会被普通的Theme
覆盖,这是为CupertinoDatePicker
应用暗模式的方法:
CupertinoTheme(
data: CupertinoThemeData(
brightness: Brightness.dark,
),
child: CupertinoDatePicker(
...
答案 2 :(得分:0)
Cupertino日期选择器具有一个名为pickerTheme的属性,该属性接受DateTimePickerTheme(),并且可以在其中指定backgroundColor。
pickerTheme: DateTimePickerTheme(
showTitle: true,
confirm: Text('Confirm',
style: TextStyle(color: Colors.red)),
cancel: Text('Cancel',
style: TextStyle(color: Colors.cyan)),
backgroundColor:
Theme.of(context).brightness == Brightness.light
? Colors.white
: Colors.grey,
),
这是完整的代码示例:
DatePicker.showDatePicker(
context,
initialDateTime: _timePicked,
dateFormat: _timeFormat,
pickerMode: DateTimePickerMode.time,
// show TimePicker
pickerTheme: DateTimePickerTheme(
showTitle: true,
confirm: Text('Confirm',
style: TextStyle(color: Colors.red)),
cancel: Text('Cancel',
style: TextStyle(color: Colors.cyan)),
backgroundColor:
Theme.of(context).brightness == Brightness.light
? Colors.white
: Colors.grey,
),
onCancel: () {
debugPrint('onCancel');
},
onChange: (dateTime, List<int> index) {
setState(() {
_timePicked = dateTime;
});
},
onConfirm: (dateTime, List<int> index) {
_timePickedValue = DateFormat.jm().format(dateTime);
state.didChange(_timePickedValue);
setState(() {
print(
'time is $_timePicked $_timePickedValue $_timePickedFormatted');
});
},
),