I am making an app in which user requests to book a butcher or make order for some amount of meat. I have two classes.
- BookingRequests (through which I see booking requests of all users from booking_collection)
- OrderRequests (through which I see order requests of all users from order_collection)
The code of both is almost similar. One displays a ListView of X-Animal slaughtering booked. The other displays X-Animal meat ordered. There is an IconButton in both. I want if I press the icon button either class data should be saved in a third collection approved_requests. I am new to flutter. Can anyone help me in doing so? Here is the code of booking.dart
class BookingRequests extends StatelessWidget {
final db = Firestore.instance;
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children: <Widget>[
StreamBuilder<QuerySnapshot>(
stream: db.collection('booking_collection').snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Column(
children: snapshot.data.documents.map((doc) {
return ListTile(
title: new Text(
"${doc.data['animal']} slaughtering booked",
),
trailing: IconButton(
icon: Icon(Icons.done),
onPressed: (){
//implementation here
},
),
);
}).toList(),
);
} else {
return SizedBox();
}
}),
],
),
);
}
}
Similarly my order.dart
class OrderRequests extends StatelessWidget {
final db = Firestore.instance;
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children: <Widget>[
StreamBuilder<QuerySnapshot>(
stream: db.collection('order_collection').snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Column(
children: snapshot.data.documents.map((doc) {
return ListTile(
title: new Text(
"${doc.data['animal']} meat ordered",
),
trailing: IconButton(
icon: Icon(Icons.done),
onPressed: (){
//implementation here
},
),
);
}).toList(),
);
} else {
return SizedBox();
}
}),
],
),
);
}
}