startActivityForResult equivalent to what in the Flutter

startActivityForResult equivalent to what in the Flutter

Navigator class may be used to obtain data information accompanying the current returns to the Route from the Route Flutter of a. Future object only needs to make a push to return await action. About Future, await, async not clear you can see the official documents , they used to implement asynchronous synchronization in the Dart.

For example, we need to start a location interface allows users to select the location they are in, we can write the following code:

Map coordinates = await Navigator.of(context).pushNamed('/location');

Here pushNamed method by the current on-screen interface to jump to a location information interface (assuming we have configured / location corresponding Route). Meanwhile pushNamed returns a Future object, we need to await the Future object as an expression of.

Then when our interface display position information after the user selects a position that we return to the previous screen to achieve the effect of current through Route pop the stack, and also the need to bring back to the previous screen data information:

Navigator.of(context).pop({"lat":43.821757,"long":-79.226392});

pop parameter is returned to the data on a screen, there is a type of data Map. Route represents the position information of the stack, await the above expression will be awakened, and the received data is transmitted over the Map.

Summary: Use Flutter in the Navigator when returned to the Stack Route Route is a push in a Future object, the interface returns to wait for the effect may be achieved by await expression, and can bring Navigator pop parameters from a Route Route Stack, then this parameter band will return to await wake of expression. Further startActivityForResult achieve a similar return in the current interface and pass parameters to the effect of an interface.

Reproduced in: https: //www.jianshu.com/p/544b1b67e9a3

Guess you like

Origin blog.csdn.net/weixin_34376562/article/details/91079909