Problem
I’m Calling An API and getting response in Variable Data ($data). When data is coming then there is no Error but when I’m getting null as response then getting this error Unhandled Exception: NoSuchMethodError: The getter ‘isEmpty’ was called on null.
When I am using the below code then it is throwing me an error:
Solution
That is because $data returns null, So I’ve Used
<code><span class="has-inline-color has-vivid-red-color">if(data?.isEmpty ?? true)</span></code>
Code language: HTML, XML (xml)
? prevents an error if the previous part of the expression results in null and ?? true results in true if the previous part of the expression is null and therefore treats == null and isEmpty the same for the if(...) check.
Now My Code is working Fine.
Thanks for reading.
Keep Coding.

With MotoShare.in, you can book a bike instantly, enjoy doorstep delivery, and ride without worries. Perfect for travelers, professionals, and adventure enthusiasts looking for a seamless mobility solution.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals