Show Get Selected Item From ListView in Flutter Android iOS Example

ListView widget has a property named as onTap() which would call each time when app user clicks on ListTile item. We can easily call any function or specific task on onTap event. On the onTap() method we would pass the selected item to stand alone function where we would print the clicked item on mobile screen using Alert dialog message box. So in this tutorial we would Show Get Selected Item From ListView in Flutter Android iOS Example Tutorial.

Contents in this project Show Get Selected Item From ListView in Flutter Android iOS Example:

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

2. Call our main MyApp class using void main runApp() method.

3. Create our main class MyApp extends with StatelessWidget. We would call ListViewWidget() here in body section.

4. Create a class named as ListViewWidget extends StatefulWidget. In this class we would make createState() method with ListViewState class. This method will allow us to use mutable state in given class tree.

5. Create our main ListView class named as ListViewState extends with State.

6. Create a List named as items in ListViewState class. We would use this list to create ListView items.

7. Create a function named as getListViewItems() with String argument. In this function we would print the selected ListView item on screen using Alert dialog box.

8. Create the ListView widget with ListTile widget in Widget build area. We would print the items using map method.

  • onTap : We are calling getListViewItems() function with data argument.

9. Complete source code for main.dart file:

Screenshots:

Show Get Selected Item From ListView in Flutter Android iOS Example

Leave a Reply

Your email address will not be published.