Send Listview Selected Item To Another Activity Screen
Complete Code For Send Listview Selected Item To Another Activity Screen In Flutter
main.dart
import 'package:flutter/material.dart'; void main() { runApp(MaterialApp( debugShowCheckedModeBanner: false, home: HomeScreen(), )); } class HomeScreen extends StatelessWidget{ final List<String> Fruitsitems = [ 'Apple', 'Bannana', 'Mango', 'Orange', 'Watermelan', 'Pinepal', 'Chikku', 'Gauvava', ]; getItemAndNavigate(String item, BuildContext context){ Navigator.push( context, MaterialPageRoute( builder: (context) => SecondScreen(FruitsItemHolder : item) ) ); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Home Activity Screen"), ), body: Center( child: ListView( children: Fruitsitems .map((data) => ListTile( title: Text(data), onTap: ()=>{ getItemAndNavigate(data, context) } )) .toList(), ), ) ); } } class SecondScreen extends StatelessWidget { final String FruitsItemHolder ; SecondScreen({Key key, @required this.FruitsItemHolder}) : super(key: key); goBack(BuildContext context){ Navigator.pop(context); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Color(0xFFCDDC39), title: Text("Second Activity Screen"), ), body: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Center(child: Text('Fruit Name = ' + FruitsItemHolder, style: TextStyle(fontSize: 22), textAlign: TextAlign.center,)), RaisedButton( onPressed: () {goBack(context);}, color: Color(0xFFCDDC39), textColor: Colors.white, child: Text('Go Back To Previous Screen'), )]) ); } }