Here is my code of on submit button :
onPressed: () async {
if (_formKey.currentState?.validate() == true) {
// Do something if the form is valid, for example, submit the data
Map<String, dynamic> data = {
"Property Title": propertyTitle,
"Property Description": propertyDescription,
"Bed Rooms": propertyBedRooms,
"Bath Rooms": propertyBathRooms,
"Property Area": propertyArea,
"Property Price": propertyPrice,
};
final collectionReference = FirebaseFirestore.instance
.collection('builderData')
.add(data);
}
},
And here is my main() where i have initialized the firebase:
void main() {
//firebase starter
WidgetsFlutterBinding.ensureInitialized();
Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
runApp(const MyApp());
}
2
Answers
Try to replace :
with the below:
and for only updating data that already existed do like below
This may work once check :
Instead of giving the TextControllers, the variables are assigned. later in the TextField() the onChange (value) is given so that if there is any change in the value of the field it gets assigned to the variable and later get into the firebase storage.