I actually have two questions.
- I'm trying to add a String type object to an existing array in Firestore like this:
addWalletToUser(coinAddress) async {
final FirebaseUser user = (await FirebaseAuth.instance.currentUser());
try {
await Firestore.instance.collection('users').document(user.uid)
.updateData({
"cryptoAddresses": FieldValue.arrayUnion(coinAddress)
});
} catch (e) {
print('error caught: $e');
return null;
}
}
This results in the following error: flutter: type 'String' is not a subtype of type 'List<dynamic>'
- My second question is why my code in this if-statement is carried out while
addWalletToUsershould return null:
if (addWalletToUser(_textController.text) != null)
Any help will be greatly appreciated!
addWalletToUserfunction isasyncso it returns aFuturewhich is not null. What you are returning inside theasyncfunction is obtained asawait addWalletToUser(text)which will now give null. Also what is the functionFieldValue.arrayUnionreturning?