dart - 如何自定义日期选择器

我正在使用 showDatePicker() 方法在我的 Flutter 应用程序中显示日期选择器。如何自定义日期选择器的颜色?

这是我的主题代码:

class CustomTheme extends Theme {
  /*
   * Colors:
   *    Primary Blue: #335C81 (51, 92, 129)
   *    Light Blue:   #74B3CE (116, 179, 206)
   *    Yellow:       #FCA311 (252, 163, 17)
   *    Red:          #E15554 (255, 85, 84)
   *    Green:        #3BB273 (59, 178, 115)
   */

  static int _fullAlpha = 255;
  static Color blueDark =  new Color.fromARGB(_fullAlpha, 51, 92, 129);
  static Color blueLight = new Color.fromARGB(_fullAlpha, 116, 179, 206);
  static Color yellow =    new Color.fromARGB(_fullAlpha, 252, 163, 17);
  static Color red =       new Color.fromARGB(_fullAlpha, 255, 85, 84);
  static Color green =     new Color.fromARGB(_fullAlpha, 59, 178, 115);

  static Color activeIconColor = yellow;


  CustomTheme(Widget child): super(
    child: child,
    data: new ThemeData(
      primaryColor: blueDark,
      accentColor: yellow,
      cardColor: blueLight,
      backgroundColor: blueDark,
      highlightColor: red,
      splashColor: green
    )
  );
}

这是我在主题中包装页面的代码:

  @override
  Widget build(BuildContext context) {
    [...]
    return new CustomTheme(
      new Scaffold(
        [...]
      )
    );
  }

最佳答案

除了确定/取消按钮之外,上述答案都有效。只需添加这个,以防有人需要帮助定制它。它是 colorScheme 和 buttonTheme 的组合。

showTimePicker(
  context: context,
  initialTime: TimeOfDay(hour: hour, minute: minute),
  builder: (BuildContext context, Widget child) {
    return Theme(
      data: ThemeData.light().copyWith(
          primaryColor: const Color(0xFF8CE7F1),
          accentColor: const Color(0xFF8CE7F1),
          colorScheme: ColorScheme.light(primary: const Color(0xFF8CE7F1)),
          buttonTheme: ButtonThemeData(
            textTheme: ButtonTextTheme.primary
          ),
      ),
      child: child,
    );
  },
);

https://stackoverflow.com/questions/50321182/

相关文章:

android - Flutter中如何检测ListView的滚动位置

flutter - 用容器包装脚手架以获得渐变背景,如何在 flutter 中将渐变设置为容器背景?

dart - Flutter如何在appbar的标题下对齐字幕?

dart - Flutter - 为什么 slider 不会在 AlertDialog 中更新?

csv - Flutter:如何从简单的电子表格中读取数据?

dart - 在小部件上显示对话框

dart - 在按钮单击时更新 flutter 中的文本字段

dart - InheritedWidget - 在 navigator.push 之后在 null

flutter - BottomAppBar float 操作按钮缺口/插图不透明

sqlite - 如何在 Flutter 中使用预填充的 sqlite 数据库我的应用程序