cdharris / flutter_duration_picker

A Flutter Widget for allowing a user to pick a duration (e.g. 5mins, 1h 30mins, etc)
MIT License
78 stars 49 forks source link

Default duration is not correct when surpassing 60min #1

Closed stubborncoder closed 6 years ago

stubborncoder commented 6 years ago

Hello, thanks for this wonderfull widget, it seems that when you set the default duration with more than 60 minutes it always defaults to 30 although the real value is correct and returns 90 minutes.

new IconButton(
                      icon: new Icon(Icons.av_timer),
                      tooltip: 'Elige duración',
                      onPressed: (() async {
                        Duration newDuration = await showDurationPicker(
                            context: context,
                            initialTime:  Duration(minutes: 90);
                        setState(() {
                          _durationCtrler.text =
                              "${newDuration.inMinutes.toString()} minutos.";
                          partidoDuration = newDuration;
                        });
                      }),

captura

cdharris commented 6 years ago

Thanks for the bug report and appreciate the screenshot too, nice styling.

Will try and get to this in a few days.

stubborncoder commented 6 years ago

Hello I tried to open a pull request but I don't have access, I think this little fix would be enough:

class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
  @override
  void initState() {
    super.initState();
    _thetaController = new AnimationController(
      duration: _kDialAnimateDuration,
      vsync: this,
    );

 // Fix for the default initial duration when it's longer than 60 minutes. INIT
    _hours = _getInitialHours(widget.duration);
 // Fix for the default initial duration when it's longer than 60 minutes. END

    _thetaTween =
        new Tween<double>(begin: _getThetaForDuration(widget.duration));
    _theta = _thetaTween.animate(new CurvedAnimation(
        parent: _thetaController, curve: Curves.fastOutSlowIn))
      ..addListener(() => setState(() {}));
  }....

int _getInitialHours (Duration duration){
    return duration.inHours.floor();
  }
solid-software commented 6 years ago

Thanks for the awesome plugin!

Added PR with a fix - it looks good to me now :) Please let us know if you can push a new version as a package.

cdharris commented 6 years ago

Many thanks for the PR, looks good to me! New version tagged and push to pub. @solid-software

solid-software commented 6 years ago

@cdharris thanks! Looks great on my end - just updated from pub :smiley: I think we can close this one.