Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: showDatePicker change colors

Tags:

colors

flutter

I'm trying to change the color of the date picker but still have the blue color in there. I tried a lot but I can't find the code that changes the blue colors (see below).

The text: Enter Date, the underline, and Cancel & OK button should all be teal as color.

showDatePicker

This is my code so far. Thanks for the support!

  TextEditingController _dateController = new TextEditingController();
  DateTime selectedDate = DateTime.now();
  var myFormat = DateFormat('d-MM-yyyy');
  Future<void> _selectDate(BuildContext context) async {
    final DateTime picked = await showDatePicker(
        context: context,
        initialDate: selectedDate,
        firstDate: DateTime(1930),
        lastDate: DateTime(2022),
        builder: (BuildContext context, Widget child) {
          return Theme(
            data: ThemeData.light().copyWith(
              colorScheme: ColorScheme.fromSwatch(
                primarySwatch: Colors.teal,
                primaryColorDark: Colors.teal,
                accentColor: Colors.teal,
              ),
            dialogBackgroundColor:Colors.white,
          ),
          child: child,
       );
    },
    );
    if (picked != null && picked != selectedDate)
      setState(() {
        selectedDate = picked;
      });
  }
like image 845
Ismail Avatar asked Oct 31 '25 06:10

Ismail


1 Answers

Try this instead

TextEditingController _dateController = new TextEditingController();
DateTime selectedDate = DateTime.now();
var myFormat = DateFormat('d-MM-yyyy');
Future<void> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(
    context: context,
    initialDate: selectedDate,
    firstDate: DateTime(1930),
    lastDate: DateTime(2022),
    builder: (BuildContext context, Widget child) {
      return Theme(
        data: ThemeData.light().copyWith(
          colorScheme: ColorScheme.fromSwatch(
            primarySwatch: Colors.teal,
            primaryColorDark: Colors.teal,
            accentColor: Colors.teal,
          ),
        dialogBackgroundColor:Colors.white,
      ),
      child: child,
   );
},
);
if (picked != null && picked != selectedDate)
  setState(() {
    selectedDate = picked;
  });
}
like image 104
henry hogan Avatar answered Nov 02 '25 19:11

henry hogan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!