I want to show list of documents from Firestore ,
and also i want if i click the button accept , I tried to show all the documents in a listview but i have a problem with the button , i want that the statut of the document change from "en cours" to "accept" but i can't get the id of the document to update the data once the text is cliqued .
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import '../rounded_button.dart';
class DemandeList extends StatelessWidget {
final db = FirebaseFirestore.instance;
String? Key ;
DemandeList({this.Key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Listes des demandes"),
centerTitle: true,
),
body: StreamBuilder<QuerySnapshot>(
stream: db.collection('ambulance')
.where("etat", isEqualTo: "en cours")
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
} else
return ListView(
children: snapshot.data!.docs.map((doc) {
return Card(
child: ListTile(
trailing: Text("Accepter",
style: TextStyle(
color: Colors.green,fontSize: 15
),
),
title: new Text(doc['id']) ,
subtitle: new Text(doc['etat']),
onTap: () => {
}
),
);
}).toList(),
);
},
),
);
}
}