akshathjain / sliding_up_panel

A draggable Flutter widget that makes implementing a SlidingUpPanel much easier!
https://pub.dartlang.org/packages/sliding_up_panel
Other
1.36k stars 379 forks source link

animatePanelToSnapPoint() in closed state triggers onPanelClosed #256

Open cudajo opened 3 years ago

cudajo commented 3 years ago

I have a SlidingUpPanel that is in closed state when I manually call the panel controller's animatePanelToSnapPoint().

Listening on the different panel states as the sliding starts - onPanelSlide(0.0) is triggered first, but then immediately followed by onPanelClosed() being triggered as well. After this, additional onPanelSlide(x.x) calls are made until the panel has reached its snap point. I assume that onPanelClosed() really shouldn't trigger in this case, right? As it already has triggered when the panel was closed, it should not trigger again since the panel is actually "opening"...

Could someone please try to reproduce this? Am I doing (or assuming) something wrong? Thanks!

cameronbatty commented 3 years ago

I too am having this issue

AlexandrKedrov commented 3 years ago

Starting from line 222 got me this fixed. I'm not sure about any drawbacks of this solution but I'm a bit skeptic that the things , done in this package, are done on purpose, and I'm missing something

    _ac = new AnimationController(
        vsync: this,
        duration: const Duration(milliseconds: 300),
        value: widget.defaultPanelState == PanelState.CLOSED
            ? 0.0
            : 1.0 //set the default panel state (i.e. set initial value of _ac)
        )
      ..addListener(() {
        if (widget.onPanelSlide != null) widget.onPanelSlide!(_ac.value);
      })
      ..addStatusListener((status) {
        if (widget.onPanelOpened != null && status == AnimationStatus.completed)
          widget.onPanelOpened!();

        if (widget.onPanelClosed != null && status == AnimationStatus.dismissed)
          widget.onPanelClosed!();
      });