【发布时间】:2020-05-18 23:15:03
【问题描述】:
我正在使用 showDatePicker() 方法在我的 Flutter 应用程序中显示一个日期选择器。如何自定义日期选择器的颜色?
这是我的主题代码:`
Widget dateOfBirth(String hintText) {
return Theme(
data: Theme.of(context).copyWith(
buttonTheme: ButtonThemeData(
textTheme: ButtonTextTheme
.accent //Colour of the text in the button "OK/CANCEL"
),
),
child: Builder(
builder: (context) {
return GestureDetector(
onTap: () async {
DateTime initialDate = DateTime(DateTime.now().year - 17,
DateTime.now().month, DateTime.now().day);
final picked = await showDatePicker(
context: context,
initialDate: initialDate,
firstDate: DateTime(DateTime.now().year - 100,
DateTime.now().month, DateTime.now().day),
lastDate: DateTime(DateTime.now().year - 17, DateTime.now().month,
DateTime.now().day),
);
if (picked != null && picked != dobSelected) {
setState(() {
});
}
return picked;
},
child: Padding(
//You can use any other widget here
padding: const EdgeInsets.symmetric(horizontal: 40.0),
child: Container(
height: 55,
width: MediaQuery.of(context).size.width,
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(3)),
color: Color(0xFFF2F2F2),
),
padding: const EdgeInsets.symmetric(horizontal: 13),
child: dobSelected == null
? Text(
'Date Of Birth',
style: TextStyle(
color: widget.isLender
? Color(0xFF8B8B8B)
: Color(0xFFB3B1B1),
fontSize: 15),
)
: Text(DateFormat('yyyy-MM-dd').format(dobSelected))),
),
);
},
),
);}
我假设您希望自定义日期选择器与您的主题不同。通常,日期选择器遵循您的主题。 这是我在主题中包装页面的代码:
@override
Widget build(BuildContext context) {
[...]
return new CustomTheme(
new Scaffold(
[...]
)
);}
我想更改日期选择器选定值的颜色
【问题讨论】: