I am currently trying to display user data like from social media after a user search for another user. have a general search user function that can search user using firebase like below
  String name = '';
  List<Map<String, dynamic>> data = [];
  addDataaUser() async {
    for (var element in data) {
      FirebaseFirestore.instance.collection('users').add(element);
    }
    print('Add User Data');
  }
  @override
  void initState() {
    super.initState();
    addDataaUser();
  }
  AppBar buildSearchField() {
    return AppBar(
      title: Card(
        child: TextField(
          decoration: InputDecoration(
            prefixIcon: Icon(Icons.search),
          ),
          onChanged: ((val) {
            setState(() {
              name = val;
            });
          }),
        ),
      ),
    );
  }
This is the ListView builder and ListTile for displaying the List of users. The onTap function leads to another page that is ProfileOthers() and in there i need the map of variable from the selected data.
//Scaffold
Scaffold(
      appBar: buildSearchField(),
      body: StreamBuilder<QuerySnapshot>(
        stream: FirebaseFirestore.instance.collection('users').snapshots(),
        builder: (context, snapshot) {
          return (snapshot.connectionState == ConnectionState.waiting)
              ? Center(
                  child: CircularProgressIndicator(),
                )
              : ListView.builder(
                  itemCount: snapshot.data!.docs.length,
                  itemBuilder: (context, index) {
                    var data = snapshot.data!.docs[index].data()
                        as Map<String, dynamic>;
                    if (data['name']
                        .toString()
                        .toLowerCase()
                        .startsWith(name.toLowerCase())) {
                      return ListTile(
                        title: Text(
                          data['name'],
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                              color: Colors.black,
                              fontSize: 16,
                              fontWeight: FontWeight.bold),
                        ),
                        subtitle: Text(
                          data['email'],
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                              color: Colors.black,
                              fontSize: 16,
                              fontWeight: FontWeight.bold),
                        ),
                        leading: CircleAvatar(
                          backgroundImage: NetworkImage(data['userImage']),
                        ),
                        onTap: () {
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                                builder: (context) => ProfileOthers(data:data)),
                          );
                        },
                      );
                    }
                    return Container();
                  });
        },
      ),
    );//End of Scaffold
This is the OthersProfile page using statefullwidget
class ProfileOthers extends StatefulWidget {
  const ProfileOthers({super.key, required this.data});
  final Map<String, dynamic> data;
  // final String dataname;
  // final String dataemail;
  // final String dataimage;
  // const ProfileOthers(
  //     {super.key,
  //     required this.dataname,
  //     required this.dataemail,
  //     required this.dataimage});
  @override
  State<ProfileOthers> createState() => _ProfileOthersState();
}
and after user click one of the data, it should display the selected users data like this
As you can see i don't know how to get the selected snapshot documents by [index] from the ListTile.
Anyone know how do i get the selected map data into another page to display it? or any other alternative??


 
    