skip to Main Content

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


  1. from the information you have provided I came to know that displayName is of Type TextEditingController and you are assigning string value to it. if you want to change the value of the TextEditingController use the text propety of the controller like this

    setState(() {
            displayName.text = data["displayName"] ?? '';
          });
    
    Login or Signup to reply.
  2. I 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 like displayName.text = data["displayName"] ?? ''. Hope it work out.

    Login or Signup to reply.
  3. This is likely due to displayName being of Type TextEditingController.

    Solution

    Instead of assigning your data directly to displayName:

    displayName = data["displayName"] ?? '';
    

    You want to do this on the .text property of your text editing controller:

    displayName.text = data["displayName"] ?? '';
    

    Hope this helps!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search