How to create timer picker in flutter?
Asked Answered
E

2

7

Is it possible to create duration timer, like in iOS in flutter?

example duration picker

Enplane answered 11/2, 2018 at 19:12 Comment(0)
E
1

There is a CupertinoTimePicker widget that does just this

Check this out

class Cupert extends StatefulWidget {

  @override
  _CupertState createState() => _CupertState();
}

class _CupertState extends State<Cupert> {
  var value = "";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: SafeArea(
        child: Column(
          children: <Widget>[
            Expanded(
              child: Center(
                child: Text(
                  "$value"
                ),
              ),
            ),
            CupertinoTimerPicker(
              mode: CupertinoTimerPickerMode.hm,
              onTimerDurationChanged: (value){
                setState(() {
                  this.value = value.toString();
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}
Exorable answered 26/3, 2020 at 21:24 Comment(0)
N
0

You can use the CupertinoTimerPicker in a dialog like this:

enter image description here

IconButton(
          icon: FaIcon(FontAwesomeIcons.clock),
          onPressed: () {
            print('timer');
            showDialog(
              context: context,
              builder: (context) {
                return SimpleDialog(
                  title: Center(child: Text('Select a Duration')),
                  children: [
                    Center(
                      child: SizedBox(
                        height: 200,
                        child: CupertinoTimerPicker(
                          onTimerDurationChanged: (value) {
                            print(value.toString());
                          },
                        ),
                      ),
                    ),
                    Row(
                      children: [
                        TextButton(
                            onPressed: () {
                              ExtendedNavigator.root.pop();
                            },
                            child: Text(
                              'Cancel',
                              style: TextStyle(color: Colors.red),
                            )),
                        TextButton(
                            onPressed: () {
                              // Todo save the selected duration to the ViewModel
                              ExtendedNavigator.root.pop();
                            },
                            child: Text('Submit')),
                      ],
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    )
                  ],
                );
              },
            );
          })
Nanceynanchang answered 7/3, 2021 at 15:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.