Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why am I getting the error "type 'int' is not a subset of type 'String' despite using .toString() in flutter?

I am currently trying to pull data from a Cloud Firestore instance. No actual data is there yet just some sample testing data.
The problem is I am coming across an error:

Another Exception was thrown: type 'int' is not a subset of type 'String'

To troubleshoot this I tried to use .toString() as shown below since the faulty data is an int but I am putting it into a Text() widget but it continues to throw the exception.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The code:

  Widget buildItem(BuildContext context, DocumentSnapshot document) {
    return ListTile(
      title: Row(
        children: [
          Expanded(
            child: Text(
              document['Name'],
              style: Theme.of(context).textTheme.headline1,
            ),
          ),
          Container(
            decoration: const BoxDecoration(
              color: kBlueLight,
            ),
            padding: const EdgeInsets.all(10),
            child: Text(
              document['Money'].toString(), //The exception is complaining about this line. I have tried with and without .toString()
              style: Theme.of(context).textTheme.displaySmall,
            ),
          )
        ],
      ),```

>Solution :

Try to replace

document['Name']

to

document.get('Name')

and replace

document['Money'].toString()

to

document.get('Money').toString()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading