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:
That is because $data returns
null, So I’ve Used
if(data?.isEmpty ?? true)
? prevents an error if the previous part of the expression results in
?? true results in
true if the previous part of the expression is
null and therefore treats
== null and
isEmpty the same for the
Now My Code is working Fine.
Thanks for reading.
- [SOLVED] Flutter:Not showing “Open for editing in Android Studio” - June 4, 2021
- [Solved] Flutter : [core/not-initialized] Firebase has not been correctly initialized. Have you added the “google-services.json” file to the project? - May 21, 2021
- [SOLVED] Flutter : NoSuchMethodError: The getter ‘isEmpty’ was called on null. - May 21, 2021