【问题标题】:Date/Time Picker Flutter : OK/CANCEL button not visible日期/时间选择器颤振:确定/取消按钮不可见
【发布时间】:2019-07-22 04:28:54
【问题描述】:

flutter 中的日期选择器小部件以白色显示确定/取消按钮,因此在白色背景中不可见。

_displayFromDate = await showDatePicker(
                    context: context,
                    initialDate: now,
                    firstDate: now,
                    lastDate: now.add(new Duration(days: 30)),
                  );

我尝试将页面主题更改为黑色的主要强调色。还是看不出来。按钮在那里,因为我可以点击它们,只是标题不可见。

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

【问题讨论】:

    标签: android ios dart flutter


    【解决方案1】:

    你需要覆盖 - buttonTheme:

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

    【讨论】:

      【解决方案2】:

      我一直调试到实际使用的小部件,因为该解决方案对我不起作用。我发现 buttonTheme 完全没有效果,而accentColor 也没有。 PrimaryColor 被使用,但不是答案中指定的颜色,而是 colorScheme.primaryColor。 对于底部的按钮,primaryColor 是 ThemeData 的 .colorScheme 部分,始终使用。要使用我的主题并仅覆盖子小部件的 primaryColor,我使用以下内容:

      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>)),
          ));
        });
      

      您会发现,在 Light-Mode 模式下,原色还负责标题部分的背景颜色(其中以大写字母表示所选日期)。不幸的是,没有办法解决这个问题。使用暗模式表面颜色。来自 Widget DatePickerHeader 的文档:

          // The header should use the primary color in light themes and surface color in dark
      

      希望这会有所帮助,而且我发现接受的答案根本不起作用!

      【讨论】:

        猜你喜欢
        • 2020-03-04
        • 2021-02-28
        • 1970-01-01
        • 1970-01-01
        • 2017-01-14
        • 1970-01-01
        • 2021-12-27
        • 1970-01-01
        • 2020-06-09
        相关资源
        最近更新 更多