Skip to content

Return data with popUntil  #30112

Closed

Description

@hgl

Navigator.pop supports returning data, I wonder why popUntil doesn't?

Ideally it should also accept a result argument, and pass it to the pop method it calls.

Would flutter team accept a such proposal?

Activity

  1. added
    c: new featureNothing broken; request for a new capability
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: routesNavigator, Router, and related APIs.
    on Mar 29, 2019
  2. hungnt-kayac commented on May 8, 2019

    @hungnt-kayac

    i have a workaround solution here. Hope that's useful for you
    https://medium.com/@hungregistermail/flutter-popuntil-with-return-data-ece825aedbd0

  3. Nico04 commented on Aug 15, 2019

    @Nico04

    i have a workaround solution here. Hope that's useful for you
    https://medium.com/@hungregistermail/flutter-popuntil-with-return-data-ece825aedbd0

    This article helped me a lot to find a workaround, thanks !

  4. afi-mobile commented on Feb 26, 2020

    @afi-mobile

    This thread was opened nearly a year ago. Is there any feedback on whether support is going to be added for adding a result to popUntil?

  5. topnax commented on Mar 2, 2020

    @topnax

    I would really appreciate this feature as well. I have no clue why is this not implemented yet.

  6. Nico04 commented on Mar 2, 2020

    @Nico04

    It will be probably implemented with the new Navigator 2.0 ?

  7. chunhtai commented on Mar 3, 2020

    @chunhtai
    Contributor

    With the page API it is possible, you will be able to decide which return value you would like to pass in to each removed route by using transition delegate, see https://github.com/flutter/flutter/pull/50362/files#diff-c798125dc01f08ce6bd3a0931482078bR810. You will get to choose how route exit the route stack, and you can specify the result when you do that. This api will be surface with Router Widget where you should be able to specify transition delegate for the MaterialApp/WidgetApp/CupterinoApp. I hope this solve your use case, and there is currently no plan to update the existing popuntil api. Let me know if you have further question.

    For more info place check out flutter.dev/go/navigator-with-router

  8. namchuai commented on Apr 28, 2020

    @namchuai

    It's seems like an overkill but I'm using provider for this.

  9. moneer-muntazah commented on Jun 6, 2021

    @moneer-muntazah

    I used pushNamedAndRemoveUntil Go back to the screen behind the one in question, and use arguments to pass your values. Better then trying to keep track of state.

  10. elliotjd1 commented on Oct 20, 2021

    @elliotjd1

    I used pushNamedAndRemoveUntil Go back to the screen behind the one in question, and use arguments to pass your values. Better then trying to keep track of state.

    That can work as a workaround, but it will use the push screen transition animation which could be confusing. Ideally we would want to keep using the pull animation to indicate that the user has actually gone back to a previous screen.

  11. rrifafauzikomara commented on Mar 10, 2022

    @rrifafauzikomara

    I fix it using shared_preferences, you can check the example and explanation here: https://stackoverflow.com/a/71426281/8291686

  12. radiKal07 commented on Mar 11, 2022

    @radiKal07

    I fix it using shared_preferences, you can check the example and explanation here: https://stackoverflow.com/a/71426281/8291686

    Very ugly for something that should've been provided out of the box by Flutter.

  13. rrifafauzikomara commented on Mar 13, 2022

    @rrifafauzikomara

    I fix it using shared_preferences, you can check the example and explanation here: https://stackoverflow.com/a/71426281/8291686

    Very ugly for something that should've been provided out of the box by Flutter.

    Very agree but instead of you can't deliver that flow/feature in your app, why not? It's just a workaround until the Flutter team provide it.

    i have a workaround solution here. Hope that's useful for you https://medium.com/@hungregistermail/flutter-popuntil-with-return-data-ece825aedbd0

    Because I try this workaround did not work on my side, so I create one

    It's seems like an overkill but I'm using provider for this.

    Also this workaround I think will work too, but in my case I'm using BLoC / GetX, so can't use this workaround.

  14. 8 remaining items

  15. EBBozkurt commented on Aug 11, 2023

    @EBBozkurt

    Is there any progress about this issue?

  16. RenatoMoratto commented on Sep 6, 2023

    @RenatoMoratto

    Any updates?

  17. chunhtai commented on Sep 6, 2023

    @chunhtai
    Contributor

    Revisiting this issue, Is the ask to return the same result for each route in the popuntil? that sounds like a dangerous api if one of them expect a different type of data. Seems to me it would be safer to call pop one by on

  18. RenatoMoratto commented on Sep 6, 2023

    @RenatoMoratto

    In my case, I would like to return the result only in the last pop(). My goal here is to replace this code:

    Navigator.of(context)
                  ..pop()
                  ..pop()
                  ..pop()
                  ..pop(true)
    

    With something like this:

    Navigator.of(context).popUntil((route) => route.isFirst, arguments: true)
    
  19. EBBozkurt commented on Sep 6, 2023

    @EBBozkurt

    I have the same situation, as @RenatoMoratto showed

  20. Uvelir commented on Apr 25, 2025

    @Uvelir

    In my situation, I have "ListScreen" => "ItemScreen" with route settings name 'itemScreen' => "FirstModalBottomSheet" => "SecondModalBottomSheet" navigation queue. I do something via cubit in SecondModalBottomSheet, and have bloc listener in ItemScreen. In listener I call Navigator.of(context).popUntil((route) => route.settings.name == 'itemScreen') to navigate from SecondModalBottomSheet to ItemScreen and right after that Navigator.of(context).pop(resultType) to navigate back from ItemScreen to ListScreen with needed returned data. That is my solution

  21. github-actions commented on Nov 12, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  22. locked as resolved and limited conversation to collaborators on Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityf: routesNavigator, Router, and related APIs.frameworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions