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),),
Share:
906
EggBender
Author by

EggBender

Updated on December 18, 2022

Comments

  • EggBender
    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);
      }
    

    How it currently looks: enter image description here

    Thanks!