Below is my flutter TextEditingController
TextEditingController displayName = TextEditingController();
when fetching document from firebase storage and assiging to the above controller, it throws an error called
Exception has occurred.
_TypeError (type 'String' is not a subtype of type 'TextEditingController')
FirebaseFirestore fireStoreRef = FirebaseFirestore.instance;
await fireStoreRef
.collection("profiles")
.doc(widget.userId)
.get()
.then((DocumentSnapshot doc) {
final data = doc.data() as Map<String, dynamic>;
setState(() {
displayName = data["displayName"] ?? '';
});
});
Can you please help me, what wrong i did here,
3
Answers
from the information you have provided I came to know that
displayName
is of TypeTextEditingController
and you are assigning string value to it. if you want to change the value of theTextEditingController
use the text propety of the controller like thisI guess
displayName
is of type TextEditingController and you cannot directly assign a string value to it. You can add string value to it’s text field likedisplayName.text = data["displayName"] ?? ''
. Hope it work out.This is likely due to
displayName
being of TypeTextEditingController
.Solution
Instead of assigning your data directly to
displayName
:You want to do this on the
.text
property of your text editing controller:Hope this helps!