[英]How can i change the background color of CupertinoDatePicker
我在我的应用程序中使用 CupertinoDatePicker。
Container(
height: 200,
padding: const EdgeInsets.all(16.0),
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
minimumYear: DateTime.now().year,
onDateTimeChanged: (DateTime value) {
print(value);
},
)
该应用程序正在使用 MaterialApp (MaterialTheme)。 有没有办法改变 CupertinoDatePicker 的背景颜色?
这是我尝试过的(将 CupertinoDatePicker 包裹在 CupertinoTheme 周围并将颜色设置为黑色),但它不起作用。
Container(
height: 200,
padding: const EdgeInsets.all(16.0),
child: CupertinoTheme(
data: CupertinoThemeData(
primaryColor: Colors.black),
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
minimumYear: DateTime.now().year,
onDateTimeChanged: (DateTime value) {
print(value);
},
),
),
)
在撰写本文时,这是不可能的,并且date_picker.dart
的源代码中有一条注释,内容如下:
// 考虑在未来设置主题的默认背景颜色。 const Color _kBackgroundColor = CupertinoColors.white;
在撰写本文时,Flutter 已为 Master 频道上的 CupertinoDatePicker 添加了 backgroundColor 属性。 见https://github.com/flutter/flutter/commit/19cdb21cb67acf51fb9b4e4e7a367d0bcd82fc7b#diff-54c54e67345e65bac63291794f109fd1它在以下版本支持:主机(#39056)v1.10.14 v1.10.13 v1.10.12 v1.10.11 v1.10.10 v1.10.9 V1 .10.8 v1.10.7 v1.10.6 v1.10.5 v1.10.4 v1.10.3 v1.10.2 v1.10.1 v1.10.0 v1.9.7 v1.9.6
您可以按如下方式设置背景颜色:
CupertinoTimerPicker(
backgroundColor: Colors.black,
initialTimerDuration: timer,
mode: CupertinoTimerPickerMode.hms,
onTimerDurationChanged: (Duration newTimer) {
setState(() {
timer = newTimer;
});
如果您为 flutter 应用程序选择深色主题,则 CupertinoDatePicker 的文本颜色将更改为白色
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.