How to make date picker 'Ok'- and 'Cancel' button text black in Dart Flutter?
906
Use this in your ThemeData
:
textButtonTheme: new TextButtonThemeData(style: TextButton.styleFrom(primary: Colors.black),),
![EggBender](https://i.stack.imgur.com/M6KMb.jpg?s=256&g=1)
Author by
EggBender
Updated on December 18, 2022Comments
-
EggBender over 1 year
I have a date picker in Flutter. I want to make the 'Ok' and 'Cancel' button text black. But I can't find the correct theme setting.
Code displaying the date picker:
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); }
Thanks!