![]() |
VOOZH | about |
Interaction with UI is an essential part of any application. During the same, there might be a need to return data from the screen. This kind of interaction can range from selecting an option to navigating to different routes through the various buttons in the UI. In this article, we will explore the process of returning data from a screen in a Flutter application.
In Flutter, it can be done using the Navigator.pop() method. We will try this by implementing a simple application.
We will need a home screen with a button. The button when tapped should load to an options screen.
It can be done like shown below:
To create a launch button to launch the selection screen and add the selection screen use the following:
We will have 2 options for the sake of simplicity and have data associate with both of them which when tapped can be returned to the home screen.
We will attach a onPressed() callback to both option 1 and option 2 which returns the data associated with each of them as shown below:
We will use snackbar by using the _navigateAndDisplaySelection() method in SelectionButton:
main.dart: