ashf
ashf

Reputation: 217

NoSuchMethodError: ‘rating’ was called on null

When the form is saved, it directs to a page where one can view the data they saved. On the page where it's viewed I'm getting the following error.

NoSuchMethodError: The getter 'rating' was called on null. Receiver: null Tried calling: rating

I check for null on that page Text(contact.rating?.toString() ?? " ") however it still shows the error.

The rating shows perfectly without an error after I hot reload and go to the saved form, but the error appears when the onPress routes to that page.

Upvotes: 1

Views: 21

Answers (1)

Akif
Akif

Reputation: 7650

You are trying to find the null control in the incorrect place. Your contact is null. So, while the rating of the contact is null and you want to set a space string in text, it should look like this:

  Text(contact?.rating?.toString() ?? " ")

Upvotes: 1

Related Questions