Flutter showTimePicker with specific 15 minute intervals
Asked Answered
I

3

6

For the showTimePicker function in Flutter used to select a time, is it possible to set a defined time interval (such as 15 minutes) to prevent users from selecting any other timing?

Currently, this is the code I have for creating a default TimePicker.

showTimePicker(
      context: context,
      initialTime: TimeOfDay.now(),
    );
Intine answered 29/6, 2020 at 5:50 Comment(0)
D
3

There is currently no way in the API, I have raised this issue: https://github.com/flutter/flutter/issues/60573

Dormie answered 30/6, 2020 at 1:4 Comment(0)
E
5

You could try using this temporal solution using: time_picker_widget

enter image description here

Copy the following code into this DEMO

showCustomTimePicker(
    context: context,
    // It is a must if you provide selectableTimePredicate
    onFailValidation: (context) =>
        showMessage(context, 'Unavailable selection.'),
    initialTime: TimeOfDay(
        hour: _availableHours.first,
        minute: 0),
    selectableTimePredicate: (time) =>
        _availableHours.indexOf(time.hour) != -1 &&
        time.minute % 15 == 0).then(
    (time) =>
        setState(() => selectedTime = time?.format(context))),
Exempt answered 24/12, 2020 at 16:53 Comment(0)
D
3

There is currently no way in the API, I have raised this issue: https://github.com/flutter/flutter/issues/60573

Dormie answered 30/6, 2020 at 1:4 Comment(0)
F
0

The package 'interval_time_picker' allows you to do exactly what you want and has the same look and feel as the default time picker:

https://pub.dev/packages/interval_time_picker

Fagen answered 21/10 at 14:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.