New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to close slider from onWillDismiss? #84
Comments
You can't access Slidable.of from the same context you need to be inside a child context. So add a builder to push yourself one context lower in the stack.
|
I know this was old but @kenthinson your answer was very helpful, Thanks! |
@kenthinson, is it possible to use this onWillDismiss? I'm not sure how to do it. as @warriorCoder, if user return false on onWillDismiss, I want to close slider. |
Any answer for onWillDismiss? Using the build context there returns null. |
@anthonysette You are welcome. |
@rbb091020 @ykaito21 I see no reason you would need to access the Slidable from inside onWillDismiss. Just return. Can you explain what you are trying to accomplish that I'm missing? Then I could advise you better about an idea. |
@kenthinson I want my slidable to close after it has been dismissed. Right now, after the user has dismissed it and fills out the form that the dismissible returns, the slidable stays open. It looks really tacky. Here's the relevant code in my app.
Instead of |
@rbb091020 If the slidable was dismissed it shouldn’t be on the screen anymore. So do you mean close automatically when the dismissal was canceled? A video of what you are trying to explain might help clarify. |
Here is a quick video of the problem. As you can see, when the user fills out the form returned from And yes, that's what I'm trying to do. Sorry, I thought dismissible just meant that you could slide the widget all the way in one direction and an action would happen. |
@rbb091020 I see what you mean. I think this is a functionality that needs to be programmed into the base slidable library. The way it's programmed now it's assuming that a full slide to the left or right is a dismissal. AKA remove from the list and screen. We have no easy way to access the Slidable from within the dismissible constructor. @letsar has said he's too busy to work on this project actively now. So forking might be your only option. I messaged him about taking over the project however as he's so busy I don't have any idea when he will respond or if he would be open to that. |
Ah, I see. Is there no work around that you can think of until then? |
@rbb091020 Ah I figured it out. You just create a SlidableController. Make sure all your slidables use it. Then call Here is an example
|
Still not working... I tried to mimic your example exactly. Can you see where I am making the error? Edit: Here is the full build method.
|
@rbb091020 Looks fine. You have tested to make sure that the .then() function is actually getting called with a debug print statement? |
Yup. Then is reached. |
@rbb091020 sounds like some kind of scope problem. No error in the console? |
Nope. No error in the console. |
@rbb091020 where are you declaring slidableController? |
@kenthinson I edited my code snippet above to include the entire stateful widget class. The slidableController is declared right before the build method. |
@rbb091020 are you having multiple bars / slidables in a list? If so you need to lift slidableController up so that all slidable share one slidableController instance not a new one for each slidable. |
Yes I do! So this is what I tried... I have a parent widget for my bar class called BudgetList. I tried lifting the state up by creating the controller there and a function that calls I also tried creating the SlidableController and passing it as a parameter to the Bar constructor, but that's just creating an instance for each slidable just like you said not to do. I feel like I'm closer though! How can I properly lift the state up? |
I'm getting no error now, but it's still not closing automatically. Here is my new BarState:
And here are the relevant portions of BudgetList:
|
@rbb091020 Sorry you are having so much trouble. I would be willing to fix the error for you for a small fee (currently unemployed and need to eat :). if you provide me all your source code I could figure it out. If you don’t want to go that route at least you know it’s possible(and not a issue with the library ) and just something wrong in your code. |
I'm closing this, since I think it's not an issue with Slidable as @kenthinson said. |
I'm using the onWillDismiss to allow the users some choices and want to close the slider when this event is triggered however nothing seems to work. I've used a controller, tried to get the SlideState using Slidable.of and neither of those options work.
The text was updated successfully, but these errors were encountered: