MOTOSHARE 🚗🏍️
Turning Idle Vehicles into Shared Rides & Earnings
From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.
With Motoshare, every parked vehicle finds a purpose.
Owners earn. Renters ride.
🚀 Everyone wins.
Problem
When I call an API, the response comes back as Variable Data ($data). When data arrives, there is no error; but, when I receive null as a response, I receive the error Unhandled. Exception: The getter ‘isEmpty’ was called on null, resulting in a NoSuchMethodError.
The code below is giving me an error when I use it:
Solution
Due to the fact that $data returns null, I’ve used
If (data?.isEmpty?? true), then
? avoids an error if the expression’s first component is null, and?? Since isEmpty and == null are treated equally for the purposes of the if(…) check, true results in true if the previous component of the expression is null.
My code is now correctly running.