Opening Flutter widget and getting the result back (startActivityForResult)

Updated 27 April 2023

Save

If you have worked on Android applications before then you must be aware that there is a function as startActivityForResult, which starts an activity and that activity returns a result to the previous activity.

Check more about our Flutter app development.

In this blog, we will see how we can achieve this in Flutter

  1. Push the new widget as the below-provided code.

    Here in the above code, you can see that we have pushed the new widget with an await prefix. Using this our function will wait till it gets some result from the next widget.
  2. Will doing the pop from the second widget add the data as the second parameter

    As we can see, we have added the result (which could be anything) to the pop function and the first widget can receive this response.
  3. To receive the result, you need to assign the await function to a variable.

    and after this, you can get the results by casting this var into the required data.

Remember to keep the await function inside an async function. It will only in this condition.

You can easily achieve the functionality of startActivityForResult just like the native Android.

That’s all for this blog. Thank you very much. This is Vedesh Kumar signing off.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home