Read More

Opening Flutter widget and getting the result back (startActivityForResult)

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. 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.

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close