Search code examples
flutterdartbuttonmobilewidget

Reset State of Slide_to_act widget in flutter


I had a problem when I slide my slide_to_act widget it works correctly and it push me to another page. But when I use nav.pop (when I turn back to old page) my slide_to_act button looks done.
I want to reset it.

                  SlideAction(
                    height: 70,
                    sliderRotate: false,
                    alignment: Alignment.centerRight,
                    onSubmit: () {
                      
                      slideAnimated_push(
                          context,
                          ConfirmPage(
                              total: summedPrice.toInt(), slevee: slevee));
                              
                    },
                    innerColor: Colors.white,
                    outerColor: StGreen,
                    elevation: 1,
                    text: 'Slide to Confirm',
                    textStyle: const TextStyle(
                      fontFamily: 'RaleWay',
                      fontSize: 20,
                      color: Colors.white,
                    ),
                  ),

rendered


Solution

  • I know i'm late but i'm also facing this issue today. After looking package files i found a solution.

    You can create a Global key with SlideActionState then assign this key to SlideAction widget. Then you will be able to reset the SlideAction state.

    You can call reset function like this :- slideActionKey.currentState!.reset();

    here is the example :-

    //Create a key like this     
    final slideActionKey = GlobalKey<SlideActionState>();
    
    SlideAction(
                      key: slideActionKey,
                      onSubmit: () {
                        // you can reset the state like this also
                        Future.delayed(const Duration(seconds: 3), () {
                          slideActionKey.currentState!.reset();
                        });
                      },
                    ))
    

    or you can reset it from anywhere you want just use the key.