Flutter Package - Duration Picker
What does it do?
- User can easily pick a duration, by turning a rotary slider
- Returns a duration in form of a Dart “Duration” object
- Features a Material Design
- It still has some weird behaviours, which will hopefully be fixed in the future
How to use it?
First create a new Flutter project the prefered way you like to use.
Just add it to your pubspec.yaml, either from pub.dev or from github if you want the newest changes as there are some important bugfixes on the Github version that are not on pub.dev
1 | dependencies: |
or
1 | dependencies: |
Then run
1 | flutter pub get |
to download the dependency.
Now import it into your current file with this line of code (or let your IDE / Text Editor do it when needed):
1 | import 'package:flutter_duration_picker/flutter_duration_picker.dart'; |
And then use it like this:
1 | import 'package:flutter/material.dart'; |
Basically like any other input widget but you can also use it like that:
1 | () async { |
The “showDurationPicker()” method returns a Future
When calling the method you really just have to pass the context as well as an initial time, which of course depends from usecase to usecase.
What could you use it for?
I used it in an app where the user could create his own recipe library and of course for a recipe you need to know how long it takes to make it. So when the user enters a new recipe I use the duration picker to get the time it takes to make the recipe. This way I can also pretty easily and uniformly display a duration later on, compared to a simple text field, where every user may enter a duration in a different unit, so seconds or hours, or with “:” or without. And this list goes on and on. This small widget solves all of these problems and more.
Have a look at the source code of the app I mentioned here if you want to see how I implemented this widget into an application (here).