Image of what text I want to customize
I am currently using the ShowDatePicker in Flutter and I was wondering if there was any way to change the text color of the highlighted widget in the image. As a note I am using flutter for Windows, this is not for a mobile application.
Here is my code:
Future<void> _selectDate(BuildContext context) async {
DateTime? selectedDate = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2000),
lastDate: DateTime(2101),
locale: const Locale('en', 'IN'),
switchToCalendarEntryModeIcon: const Icon(Icons.edit_calendar_outlined),
switchToInputEntryModeIcon: const Icon(Icons.edit_outlined),
builder: (BuildContext context, Widget? child) {
return Theme(
data: ThemeData.dark().copyWith(
colorScheme: const ColorScheme.dark(
primary: Colors.blueAccent, // header background color
onPrimary: Colors.white, // header text color
onSurface: Colors.white, // body text color
surface: Colors.black,
),
buttonTheme: const ButtonThemeData(
textTheme: ButtonTextTheme.primary, // Button text color
),
scrollbarTheme: const ScrollbarThemeData(
thumbVisibility: MaterialStatePropertyAll(true),
thumbColor: MaterialStatePropertyAll(Colors.blueAccent),
),
iconButtonTheme: const IconButtonThemeData(
style: ButtonStyle(
iconColor: MaterialStatePropertyAll(Colors.white),
),
),
datePickerTheme: const DatePickerThemeData(
dividerColor: Colors.blueAccent,
),
),
child: child!,
);
},
);
if (selectedDate != null) {
setState(() {
String formattedDate =
"${selectedDate.day}/${selectedDate.month}/${selectedDate.year}";
dateController.text = formattedDate;
});
}
}
I tried setting the ColorScheme property with various types, setting diffrent properties in the datePickerTheme and tried adding the theme using ButtonStyle and ListTileStyle. None of them seemed to work and I’m not sure if I missed anything.
Christiaan Van Jaarsveldt is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.