Property can't be unconditionally accessed because the receiver can be null
143
Since both of your values are nullable you have to adjust your code to do the conditional check. Add some guard-like checks before:
bool doesTourExceedsVenueCapacity(
ToursRecord? tourRecord,
int? venueCapacity,
) {
final passengers = tourRecord?.passengers;
if (venueCapacity == null) return false //adjust return value
if (passengers == null) return false // adjust return value
return passengers > venueCapacity; // ? true : false unnecessary here
}
Author by
Roggie
Updated on January 05, 2023Comments
-
Roggie over 1 year
I am trying to address the
null
safety on the following function. Nestingif
statements doesn't seem to work.bool doesTourExceedsVenueCapacity( ToursRecord? tourRecord, int? venueCapacity, ) { return tourRecord.passengers > venueCapacity ? true : false; }