How to check object in model class when its null sometime in response in flutter

Issue

Error is shown when subscription object is null which is the required type parameter.

Error: NoSuchMethodError: The method ‘[]’ was called on null.
Receiver: null
Tried calling:

How to solve this error, arrived on when subscription object is null.

I also shared my model class download link
https://drive.google.com/file/d/1gcOKQ49RaEF3w0NBPpijGtbGUdSkgZrx/view?usp=sharing

Solution

please try with this

if(json['subscription'] !=null) { subscription = Subscription.fromJson(json['subscription']); }

Answered By – Mohammad Faizan

Answer Checked By – Marilyn (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *