pickTime function

Future<TimeOfDay?> pickTime({
  1. required BuildContext context,
  2. required TimeOfDay initialTime,
})

Implementation

Future<TimeOfDay?> pickTime(
    {required BuildContext context, required TimeOfDay initialTime}) async {
  TimeOfDay? time = await showTimePicker(
    context: context,
    initialTime: initialTime,
    builder: (context, child) {
      return Theme(
        data: ThemeData(
          colorScheme: ColorScheme(
              brightness: Theme.of(context).brightness,
              primary: Theme.of(context).primaryColor,
              onPrimary: Colors.white,
              secondary: Colors.white,
              onSecondary: Colors.black,
              error: Colors.red,
              onError: Colors.white,
              background: Theme.of(context).cardColor,
              onBackground: Colors.white,
              surface: Theme.of(context).brightness == Brightness.light
                  ? AppColors.white
                  : Colors.black54,
              onSurface: Theme.of(context).brightness == Brightness.light
                  ? Colors.black
                  : Colors.white),
        ),
        child: MediaQuery(
          data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: true),
          child: child!,
        ),
      );
    },
  );
  return time;
}