Flutter Send ListView Selected Item to Another Activity Screen Example

In flutter we can easily access the ListView selected item value but the main task is to Flutter Send ListView Selected Item to Another Activity Screen and receive the sent value on next screen using super(key: key) method. This method would allow us to receive values sent by another activity screen on navigation time. In this tutorial we would use the Navigator.push() method to navigate between screens and along with it we would send the selected item value to next activity in flutter android iOS app example tutorial.

Contents in this project Flutter Send ListView Selected Item to Another Activity Screen Android iOS Example Tutorial:

1. Import material.dart package in your app’s main.dart file.

2. Create flutter’s default void main runApp() method and here we would call our first home screen named as HomeScreen(). This would be our first screen for app.

3. Create our main first screen class named as HomeScreen extends StatelessWidget.

4. Create a List <String> named as items in HomeScreen class. Using this List we would initialize the List Items values.

5. Create a function named as getItemAndNavigate() with Context and String argument. We would call this function on ListView item click event. Inside this function we would navigate to another activity screen and along with it we would send the selected item value to next screen using Navigator.push() method.

6. Create ListView in widget build area in HomeScreen class. Here we would use the items List to populate the List items.

  • onTap : Call the getItemAndNavigate() function on onPress event with selected item and application context.

7. Now our first screen work has done. Next step is to create a class named as SecondScreen extends StatelessWidget. This would be our second screen of app.

8. Create a final String variable named as itemHolder. We would use this variable to receive the sent value.

9. Create constructor with same class name and receive the send value to itemHolder variable in SecondScreen class.

10. Create a function named as goBack() with context parameter. In this function we would call the Navigator.pop(context) method to go back to previous screen.

11. Create 1 Text widget and 1 Raised button widget in Widget build area of SecondScreen class. The text widget is used to display the selected ListView item and Raised button in used to go back to previous screen.

12. Complete source code for main.dart file:

Screenshots:

Flutter Send ListView Selected Item to Another Activity Screen Example

2 Comments

  1. Hello, First of all thank you for you example it helps me alot. But I have one issue that I have to send multiple data from listview to next screen. So can you help me that how can I do that. I am waiting for your response and thak you in advance.

Leave a Reply

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