![]() |
VOOZH | about |
Interaction with the UI is an integral part of any application. But more often than not, the information needs to be sent from one screen to another. For instance, say you need to pass data regarding a selected or tapped component of the UI to another route(i.e., page). In this article, we will explore in detail the process of sending data to another screen by building a simple application.
For better understanding, we will build a Task memo app that lists all the pending tasks on the home screen, and when any of the tasks is clicked, a respective detailed description of the task is shown on another page. Here, we will be passing the data from the Home screen (the task that is tapped on) to a description screen.
Create a new Flutter application using the command Prompt. To create a new app, write the below command and run it.
flutter create app_nameTo know more about it refer this article: Creating a Simple Application in Flutter
A simple way to define the task class is shown below:
Use the ListView to generate the list of task. For the sake of simplicity we will be creating a list of 10 tasks as follows:
Now create a home screen where the list can be displayed using a StatelessWidget as follow:
Create a page that extracts the task_name (name of the task) and the description of the task from the home screen as an argument using the ModelRoute.of() method as shown below:
Now pass the description and task_name as a RouteSettings argument using assigning a callback function to the onTap() function that uses the Navigator.push() method of the Navigator class as shown below:
main.dart: