naser
naser

Reputation: 33

How to add text beside hour and minute in CupertinoDatePicker

I am using CupertinoDatePicker to allow user to select specific time in the current day, but i want to show text beside the selected hour and selected minute, is there any way to do this ?

This is what i am expecting

enter image description here

This is what i got

enter image description here

CupertinoDatePicker(
    mode: CupertinoDatePickerMode.time,
    use24hFormat: true,
    onDateTimeChanged: (value){
      setState(() {
        print(value);
      });
    },
)

Upvotes: 2

Views: 1725

Answers (2)

Berkan Aslan
Berkan Aslan

Reputation: 53

You can use CupertinoTimerPicker.

Referance: CupertinoTimerPicker

Upvotes: 0

ibhavikmakwana
ibhavikmakwana

Reputation: 10091

You are looking for the CupertinoTimerPicker widget.

It comes up with the default labels.

example:

12 hours 12 minute

Code for the same:

          CupertinoTimerPicker(
            onTimerDurationChanged: (value) {
              setState(() {
                print(value);
              });
            },
            mode: CupertinoTimerPickerMode.hm,
            backgroundColor: Colors.red,
            initialTimerDuration: Duration(hours: 12, minutes: 12),
          ),

But, If you need the custom label as in h, m, and s in your case, you've to make a custom Cupertino time picker using existing code (from Flutter SDK).

Upvotes: 0

Related Questions