FrostByte
FrostByte

Reputation: 55

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.

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,
            ),
          )
        ],
      ),```

Upvotes: 1

Views: 58

Answers (1)

My Car
My Car

Reputation: 4566

Try to replace

document['Name']

to

document.get('Name')

and replace

document['Money'].toString()

to

document.get('Money').toString()

Upvotes: 2

Related Questions