How to customize a TimePicker widget in Flutter

Viewed 3266

enter image description here

How can you change the Purple selection color, Purple border color, time text color and Hour and Minute color from the input time picker widget, can't seem to find the properties in TimePickerThemeData

2 Answers
showTimePicker(
                  context: context,
                  initialTime: TimeOfDay(hour: 10, minute: 47),
                  builder: (context, child) {
                    return Theme(
                      data: ThemeData.light().copyWith(
                        colorScheme: ColorScheme.light(
                          // change the border color
                          primary: Colors.red,
                          // change the text color
                          onSurface: Colors.purple,
                        ),
                        // button colors 
                        buttonTheme: ButtonThemeData(
                          colorScheme: ColorScheme.light(
                            primary: Colors.green,
                          ),
                        ),
                      ),
                      child: child,
                    );
                  },
                );

Result:

enter image description here

You are able to use states on your theme too! Controlling the styles when making some action (like selected or focused actions).

Here an example:

final theme = ThemeData.light().copyWith(
  timePickerTheme: TimePickerThemeData(
    backgroundColor: Colors.green.shade200,
    hourMinuteColor: MaterialStateColor.resolveWith((states) =>
        states.contains(MaterialState.selected)
            ? Colors.blue.withOpacity(0.2)
            : Colors.orange),
    hourMinuteTextColor: MaterialStateColor.resolveWith((states) =>
        states.contains(MaterialState.selected)
            ? Colors.pink
            : Colors.deepPurple),
    dialHandColor: Colors.pink.shade800,
    dialBackgroundColor: Colors.purple.withOpacity(0.5),
    dialTextColor: MaterialStateColor.resolveWith((states) =>
        states.contains(MaterialState.selected)
            ? Colors.green
            : Colors.black),
    entryModeIconColor: Colors.yellow
    ),
    textTheme: TextTheme(
      overline: TextStyle(
        color: Colors.red,
      ),
    ),
    textButtonTheme: TextButtonThemeData(
        style: ButtonStyle(
      backgroundColor: MaterialStateColor.resolveWith((states) => Colors.black),
      foregroundColor: MaterialStateColor.resolveWith((states) => Colors.green),
      overlayColor: MaterialStateColor.resolveWith((states) => Colors.pink),
    )));

enter image description here enter image description here enter image description here

Related