Debug School

rakesh kumar
rakesh kumar

Posted on

Flutter Errors:type 'Null' is not a subtype of type 'String' in type cast

Reason 1
Debug
when i debug i got print nothing

print("payDate: $payDate");
Enter fullscreen mode Exit fullscreen mode
payDate: 
Enter fullscreen mode Exit fullscreen mode

Existing code

var payDate = json['pay_date'];
Enter fullscreen mode Exit fullscreen mode

Solution
i change small p to capital P as data base field name is Pay_date

var payDate = json['Pay_date'];
Enter fullscreen mode Exit fullscreen mode

Reason 2

print("influencerAdminId: $influencerAdminId");
Enter fullscreen mode Exit fullscreen mode
influencerAdminId:[]
Enter fullscreen mode Exit fullscreen mode

my existing code is

final String influencerAdminId;
============or===========
final List<String> influencerAdminId;
Enter fullscreen mode Exit fullscreen mode

solution

 final List<int> influencerAdminId;
Enter fullscreen mode Exit fullscreen mode

Reason 3
print("statusDate: $statusDate");
in response if it is null

statusdate: {291: null},
Enter fullscreen mode Exit fullscreen mode

Solution

 var statusDate = json['statusdate'] != null
        ? (json['statusdate'] as Map).map((key, value) => MapEntry(key.toString(), safeString(value)))
        : null;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)