How to solve the “Type Null is not a subtype of type …” error?

You are running with Null Safety enabled in your project. You have declared your all fields required and non-null in your Data Model Class.

Your API response is having a field absent or having a null value, that’s why you are facing this issue.

Solution: Replacing int with int? (making fields optional will resolve issue).

Leave a Comment