[英]Date/Time Picker Flutter : OK/CANCEL button not visible
The date picker widget in flutter displays the ok/cancel buttons in white, and therefore are not visible in a white background. flutter 中的日期选择器小部件以白色显示确定/取消按钮,因此在白色背景中不可见。
_displayFromDate = await showDatePicker(
context: context,
initialDate: now,
firstDate: now,
lastDate: now.add(new Duration(days: 30)),
);
I've tried changing the page theme with primary, accent colours as black.我已经尝试将页面主题更改为黑色。 Still not visible.还是看不见。 The button are there, because I can tap on them, just the titles aren't visible.按钮在那里,因为我可以点击它们,只是标题不可见。
[✓] Flutter (Channel master, v1.2.3-pre.67, on Mac OS X 10.13.6 17G5019, locale
en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.2)
[✓] Connected device (2 available)
I debugged this all the way down to the actual Widgets used because the solution didn't work for me.我一直调试到实际使用的小部件,因为该解决方案对我不起作用。 What I found is that buttonTheme has absolutely no effect and accentColor doesn't either.我发现 buttonTheme 绝对没有效果,accentColor 也没有。 PrimaryColor is used but not the one specified in the answer but rather colorScheme.primaryColor.使用了 PrimaryColor 但不是在答案中指定的那个,而是 colorScheme.primaryColor。 For the buttons at the bottom, primaryColor is of the .colorScheme part of ThemeData is used at all times.对于底部的按钮,primaryColor 是 ThemeData 的 .colorScheme 部分,始终使用。 To use my theme and override just the primaryColor for the child Widgets, I use the following:要使用我的主题并仅覆盖子小部件的主颜色,我使用以下内容:
final DateTime picked = await showDatePicker(
context: context,
builder: (context, child) {
return SingleChildScrollView(
child: Theme(
child: child,
data: Theme.of(context).copyWith(
colorScheme: Theme.of(context)
.colorScheme
.copyWith(primary: <Desired Color>)),
));
});
You will find that on Light-Mode the primary color is also responsible for the background color of the header section (where it says the selected date in large letters).您会发现,在 Light-Mode 上,主色还负责标题部分的背景颜色(它用大写字母表示所选日期)。 Unfortunately there's no way around that.不幸的是,没有办法解决这个问题。 On Dark-Mode surface color is used.在暗模式下使用表面颜色。 From the documentation of Widget DatePickerHeader:来自 Widget DatePickerHeader 的文档:
// The header should use the primary color in light themes and surface color in dark
Hope this helps and again, the accepted answer doesn't work at all from what I've found!希望这会有所帮助,并且根据我的发现,接受的答案根本不起作用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.