如何在 Dart Flutter 中使日期选择器 'Ok'- 和 'Cancel' 按钮文本变黑?
How to make date picker 'Ok'- and 'Cancel' button text black in Dart Flutter?
我在 Flutter 中有一个日期选择器。我想将 'Ok' 和 'Cancel' 按钮文本设为黑色。但是我找不到正确的主题设置。
显示日期选择器的代码:
Future<void> selectDate(
BuildContext context,
DateTime initialDate,
TextEditingController controller,
Function(DateTime picked, TextEditingController controller) onDatePicked,
String label) async {
final DateTime picked = await showDatePicker(
context: context,
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData(
primarySwatch: Colors.grey,
splashColor: Colors.black,
textTheme: TextTheme(
subtitle1: TextStyle(color: Colors.black),
button: TextStyle(color: Colors.black),
),
accentColor: Colors.black,
colorScheme: ColorScheme.light(
primary: Colors.green[600],
primaryVariant: Colors.black,
secondaryVariant: Colors.black,
onSecondary: Colors.black,
onPrimary: Colors.white,
surface: Colors.black,
onSurface: Colors.black,
secondary: Colors.black),
dialogBackgroundColor: Colors.white,
),
child: child,
);
},
initialDate: initialDate.toLocal(),
firstDate: DateTime(2015, 8).toLocal(),
lastDate: DateTime(2101).toLocal(),
fieldLabelText: label);
if (picked != null) onDatePicked(picked, controller);
}
目前的情况:
谢谢!
在你的ThemeData
中使用这个:
textButtonTheme: new TextButtonThemeData(style: TextButton.styleFrom(primary: Colors.black),),
我在 Flutter 中有一个日期选择器。我想将 'Ok' 和 'Cancel' 按钮文本设为黑色。但是我找不到正确的主题设置。
显示日期选择器的代码:
Future<void> selectDate(
BuildContext context,
DateTime initialDate,
TextEditingController controller,
Function(DateTime picked, TextEditingController controller) onDatePicked,
String label) async {
final DateTime picked = await showDatePicker(
context: context,
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData(
primarySwatch: Colors.grey,
splashColor: Colors.black,
textTheme: TextTheme(
subtitle1: TextStyle(color: Colors.black),
button: TextStyle(color: Colors.black),
),
accentColor: Colors.black,
colorScheme: ColorScheme.light(
primary: Colors.green[600],
primaryVariant: Colors.black,
secondaryVariant: Colors.black,
onSecondary: Colors.black,
onPrimary: Colors.white,
surface: Colors.black,
onSurface: Colors.black,
secondary: Colors.black),
dialogBackgroundColor: Colors.white,
),
child: child,
);
},
initialDate: initialDate.toLocal(),
firstDate: DateTime(2015, 8).toLocal(),
lastDate: DateTime(2101).toLocal(),
fieldLabelText: label);
if (picked != null) onDatePicked(picked, controller);
}
目前的情况:
谢谢!
在你的ThemeData
中使用这个:
textButtonTheme: new TextButtonThemeData(style: TextButton.styleFrom(primary: Colors.black),),