Skip to content
Advertisement

How to fix The following _CastError was thrown building: type ‘Future’ is not a subtype of type ‘List’ in type cast

JavaScript

I had tried to add behind the future and it doesn’t solve the problem. Moreover, there is a problem with the itemcount, so I left it with a number instead of add snapshot.data!.length() because I am not sure why there is an error with snapshot.data!.length() for itemcount.

Advertisement

Answer

Here is full working code.

At first because pic() returns Future, you need to use ‘await’ or ‘then’ to get a response.
https://dart.dev/codelabs/async-await

Because of that, below sentence cause error as you provided.
But because it is not necessary in this case, I get rid of this.

JavaScript

If you want use pic() method, just call like below.
(But in this case, you cannot call like this.)

JavaScript

You’ve already used ‘FutureBuilder’, you don’t need to call pic() again.
You just use snapdata’s data incase of snapdata has a data.

enter image description here

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement