我會在數(shù)據(jù)流中添加空數(shù)據(jù)。如果我再次添加數(shù)據(jù),它將顯示過去的條目,并且該過程會重復(fù)。換句話說,寫入的數(shù)據(jù)會顯示在后續(xù)文檔中(一旦創(chuàng)建)。
onPressed: () async {
//save data to firebase
await db.collection("Contacts").add(
{
'Name': widget.contact.name,
'PhoneNumber': widget.contact.phoneNumber,
'Location': widget.contact.location,
'Birthday': widget.contact.birthday,
'Notes': widget.contact.notes
},
);
widget.contact.name = oneController.text;
widget.contact.phoneNumber = int.parse(twoController.text);
widget.contact.location = threeController.text;
widget.contact.birthday = int.parse(sixController.text);
widget.contact.notes = sevenController.text;
Navigator.pushReplacementNamed(context, "/second");
})
在添加DB之前,需要設(shè)置控制器的值。這就是為什么要在第一次添加null值。嘗試如下所示替換代碼的優(yōu)先級: