Home > OS >  TextFormField to Firebase Firestore
TextFormField to Firebase Firestore

Time:06-26

it only uploads one of them ( "Doc": docs.text, ), all the other ones are not being uploaded.

onTap: () async {
                    await firestor.add({
                      "Doc": docs.text,
                      "gear": gear.text,
                      "price": price.text,
                      "machine": machine.text,
                      "add": add.text,
                      "desc": desc.text,
                      "ph": ph.text,
                      "wph": wph.text,
                    });
final docs = TextEditingController();
  final gear = TextEditingController();
  final machine = TextEditingController();
  final price = TextEditingController();
  final add = TextEditingController();
  final desc = TextEditingController();
  final ph = TextEditingController();
  final wph = TextEditingController();

CodePudding user response:

I noticed you didn't add your new data into a specific collection. Before:firestore.add After:firestore.collection('your collection name').add

                  FlatButton(
                    onPressed: () {
                      messageTextController.clear();
                      _firestore.collection('messages').add(
                        {
                          'text': messageText,
                          'sender': loggedInUser.email,
                        }
                      );
                      print("sent");

                      //Implement send functionality.
                    },
                    child: Text(
                      'Send',
                      style: kSendButtonTextStyle,
                    ),
                  ),

CodePudding user response:

This worked properly.

this is how I instantiated Firestore

final firestor = FirebaseFirestore.instance.collection("toyota");

These are the TextFormField Controllers

final docs = TextEditingController();
  final gear = TextEditingController();
  final machine = TextEditingController();
  final price = TextEditingController();
  final add = TextEditingController();
  final desc = TextEditingController();
  final ph = TextEditingController();
  final wph = TextEditingController();

And this is how I Uploaded the form in Firestore

 onTap: () async {
                    await firestor.add({
                      "Doc": docs.text,
                      "gear": gear.text,
                      "price": price.text,
                      "machine": machine.text,
                      "add": add.text,
                      "desc": desc.text,
                      "ph": ph.text,
                      "wph": wph.text,
                    });
                  },
  • Related