dart - 如何自定义日期选择器
问题描述
我正在使用该showDatePicker()
方法在我的颤振应用程序中显示日期选择器。如何自定义日期选择器的颜色?
这是我的主题代码:
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,
);
},
);
推荐阅读
- angular - 无法使用键盘输入日期
- sql - PostgreSQL 命令在我尝试在 psql shell 中再次运行它们之前不起作用
- unity3d - 让绳子“摇摆”
- javascript - 找不到页面和默认主页总是重定向到主页 - React Router
- jquery - 如何在 ASP.NET Razor 视图中使用 jQuery 将模型发送回 ASP.NET 控制器
- ios - iOS:QLPreviewController 不预览 Pages 或 Word 文档
- c++ - CPLEX - Adding Lazy Constraints with variables of different type lead to InvalidCutException
- go - 访问切片 Golang 模板中的结构中的特定字段
- ios - 为什么这个警报不让我的视图控制器释放?
- mysql - MySQL 使用触发器将数据排序到其他表 - 已解决