我发现很难更改深色主题中的日期选择器年份,因为不可见如何解决此问题。更改深色主题的年份和箭头按钮的颜色。
这是我的日期选择器主题代码
datePickerTheme: DatePickerThemeData(
weekdayStyle: const TextStyle(color: Colors.white),
headerForegroundColor: Colors.white,
dayForegroundColor: MaterialStateColor.resolveWith((states) => Colors.white),
todayForegroundColor: MaterialStateColor.resolveWith((states) => Colors.white),
backgroundColor: const Color(0xff31343b),
elevation: .5,
yearForegroundColor: MaterialStateColor.resolveWith((states) => Colors.white),
),
需要更改 flutter 中深色主题的日期选择器颜色。
看起来它可能是由主题配色方案的
onSurface
属性控制的。如果您不想更改整个应用程序的 onSurface
,您可以改为提供 showDatePicker
这个构建器:
builder: (context, child) {
return Theme(
data: Theme.of(context).copyWith(
colorScheme: Theme.of(context)
.colorScheme
.copyWith(onSurface: Colors.red)), //change to your desired color
child: child!);
},
我不确定这是否能完全解决问题,但你可以尝试一下。