Home > Enterprise >  When I insert new fields using new method then deleting previous fields and over writing
When I insert new fields using new method then deleting previous fields and over writing

Time:12-07

When I insert new fields using new method then deleting previous fields and over writing. How to add new fields without replace in previous fields ?

this is my code.

void displayMessage() {
    List<CheckBoxModel> checked =
        checkboxes.where((element) => element.value).toList();
    String result = '';
    checked.forEach((element) {
      result = result   element.title;
    });
    final sp = context.read<SignInProvider>();
    FirebaseFirestore.instance
        .collection("users")
        .doc(sp.uid)
        .set({
      "firstWord": value,
      "disease": result,
    });
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => const ChildDetailsScreen()),
    );
    _saveDataFirstWord(value!);
  }
}

How to do that?

CodePudding user response:

To insert new fields without deleting previous fields, don't use set, use update instead.

Like so:

    FirebaseFirestore.instance
        .collection("users")
        .doc(sp.uid)
        .update({
      "firstWord": value,
      "disease": result,
    });
  • Related