格式 datePicker Header - Flutter
Format datePicker Header - Flutter
如何设置我的日期选择器的格式,使 header 中的文本为黑色,按钮文本为黑色?这是我的代码:
Future<Null> _selectDate(BuildContext context) async {
DateFormat formatter =
DateFormat('dd/MM/yyyy'); //specifies day/month/year format
final DateTime picked = await showDatePicker(
context: context,
initialDate: selectedDate,
firstDate: DateTime(1901, 1),
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData.light().copyWith(
//primaryColor: kPrimaryColor,
colorScheme: ColorScheme.light(primary: kPrimaryColor),
buttonTheme: ButtonThemeData(
textTheme: ButtonTextTheme.primary
),),
child: child,
);
},
lastDate: DateTime(2100));
这是日期选择器当前的样子:
要设置按钮文本颜色,您可以使用 colorScheme
作为 buttonTheme
。
要设置 header 文本颜色,您可以使用 onPrimary
。
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData.light().copyWith(
colorScheme: ColorScheme.light(
primary: kPrimaryColor,
onPrimary: Colors.black,),
buttonTheme: ButtonThemeData(
colorScheme: Theme.of(context)
.colorScheme
.copyWith(primary: Colors.black),
),
),
child: child,
);
}),
结果:
如何设置我的日期选择器的格式,使 header 中的文本为黑色,按钮文本为黑色?这是我的代码:
Future<Null> _selectDate(BuildContext context) async {
DateFormat formatter =
DateFormat('dd/MM/yyyy'); //specifies day/month/year format
final DateTime picked = await showDatePicker(
context: context,
initialDate: selectedDate,
firstDate: DateTime(1901, 1),
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData.light().copyWith(
//primaryColor: kPrimaryColor,
colorScheme: ColorScheme.light(primary: kPrimaryColor),
buttonTheme: ButtonThemeData(
textTheme: ButtonTextTheme.primary
),),
child: child,
);
},
lastDate: DateTime(2100));
这是日期选择器当前的样子:
要设置按钮文本颜色,您可以使用 colorScheme
作为 buttonTheme
。
要设置 header 文本颜色,您可以使用 onPrimary
。
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData.light().copyWith(
colorScheme: ColorScheme.light(
primary: kPrimaryColor,
onPrimary: Colors.black,),
buttonTheme: ButtonThemeData(
colorScheme: Theme.of(context)
.colorScheme
.copyWith(primary: Colors.black),
),
),
child: child,
);
}),
结果: