简体   繁体   English

日期/时间选择器颤动:确定/取消按钮不可见

[英]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)

在此处输入图片说明

You need to overwrite - buttonTheme:您需要覆盖 - buttonTheme:

theme: ThemeData(
            buttonTheme: ButtonThemeData(textTheme: ButtonTextTheme.accent),
            accentColor: Colors.black,
            primaryColor: Colors.black)

在此处输入图片说明

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.

相关问题 日期选择器的OK / CANCEL按钮文本已在牛轧糖中更改为其他语言(Moto G4 plus) - date picker OK/CANCEL button text changed to some other language in nougat(Moto G4 plus) 日期选择器对话框中确定和取消按钮的文本颜色没有改变,仅保持白色 - Text Colour of OK & Cancel button in Date picker dialogue is not changing and remains white only Xamarin - 在自定义选择器上隐藏取消按钮或将其更改为确定 - Xamarin - Hide Cancel button or change it for Ok on Custom Picker 如何在 Xamarin.Forms 的日期选择器中隐藏“取消”按钮 - How to hide Cancel button in date picker in Xamarin.Forms 单击取消按钮上的日期选择器对话框时如何完成活动 - How to finish activity when date picker dialog on cancel button is clicked 如何在取消按钮上清除时间选择器的共享首选项? - How to Clear shared Preference for a Time Picker on Cancel button? 日期和时间选择器已完成按钮对齐 - Date and time picker done button alignment 后退按钮的确定/取消对话框 - OK/Cancel dialog for Back Button AlertDialog…没有“确定”按钮,只有“取消” - AlertDialog…no OK button, only Cancel TimePickerDialog CANCEL 和 OK 按钮未显示 - TimePickerDialog CANCEL and OK button not showing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM