I am trying to add a subcollection to the main collection in this case users. I want that every user can add their own medication and it store in Users => medication.
User collection
medication subcolletion
this is the collection of users-
Future addUserDetails(String name, String surname, String email, int age,
int weight, String gender, int phonenumber) async {
await FirebaseFirestore.instance.collection('users').add({
'name': name,
'surname': surname,
'email': email,
'age': age,
'weight': weight,
'gender': gender,
'phonenumber': phonenumber
});
This is the collection for medication - (in a different page)
SizedBox(height: 4),
OutlinedButton(
onPressed: () {
Map<String, dynamic> data = {
'Triggers': _triggersController.text +
(', ') +
_triggersController2.text,
'Preventer inhaler': _preventController.text,
'Reliever inhaler': _relieverController.text,
'Other medication': _othermedicationController.text
};
FirebaseFirestore.instance
.collection('Medication')
.add(data);
},