Date/Time Picker Flutter : OK/CANCEL button not visible Date/Time Picker Flutter : OK/CANCEL button not visible dart dart

Date/Time Picker Flutter : OK/CANCEL button not visible


You need to overwrite - buttonTheme:

theme: ThemeData(            buttonTheme: ButtonThemeData(textTheme: ButtonTextTheme.accent),            accentColor: Colors.black,            primaryColor: Colors.black)

enter image description here


I debugged this all the way down to the actual Widgets used because the solution didn't work for me. What I found is that buttonTheme has absolutely no effect and accentColor doesn't either. PrimaryColor is used but not the one specified in the answer but rather colorScheme.primaryColor.For the buttons at the bottom, primaryColor is of the .colorScheme part of ThemeData is used at all times. To use my theme and override just the primaryColor for the child Widgets, I use the following:

final DateTime picked = await showDatePicker(  context: context,  builder: (context, child) {    return SingleChildScrollView(        child: Theme(      child: child,      data: Theme.of(context).copyWith(          colorScheme: Theme.of(context)              .colorScheme              .copyWith(primary: <Desired Color>)),    ));  });

You will find that on Light-Mode the primary color is also responsible for the background color of the header section (where it says the selected date in large letters). Unfortunately there's no way around that. On Dark-Mode surface color is used. From the documentation of Widget DatePickerHeader:

    // The header should use the primary color in light themes and surface color in dark

Hope this helps and again, the accepted answer doesn't work at all from what I've found!