1

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.

ashf
  • 187
  • 2
  • 13
  • 2
    Does this answer your question? [What is a NoSuchMethod error and how do I fix it?](https://stackoverflow.com/questions/64049102/what-is-a-nosuchmethod-error-and-how-do-i-fix-it) – nvoigt Nov 12 '20 at 19:51
  • 2
    Your null check does not include "contact" itself. You need to check that too. – nvoigt Nov 12 '20 at 19:52
  • 1
    Thanks @nvoigt , yes the link was helpful. Thank you. – ashf Nov 12 '20 at 19:59

1 Answers1

1

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() ?? " ")
Akif
  • 7,098
  • 7
  • 27
  • 53
  • 1
    Thanks this cleared the error, however it is not showing any data on the page it directs to. It only will if I hot reload. – ashf Nov 12 '20 at 19:56
  • 1
    Ok, then the new problem is about a new question. You can share the total code of your page. – Akif Nov 12 '20 at 19:58