I’m getting this error.
I’m on section 1 chapter 2,
getting an error when adding a RecipeDetail page to the app.
Please provide guidance on how to fix that error. and continue my learning.
I got similar error earlier, but I don’t think referencing final project can enhance my learning much, so I firstly verified the code thoroughly and that I followed the instructions correctly. Thereafter, I recalled that since “hot reload” and “hot restart” were not effecting the change, I had to rebuild (re-run) the app. That cleared the error for me.
@jomoka I’d add another hint to your list (disclaimer: I’m only a beginner in Flutter) because I had the same issue as @afajansari at the same place although I doubly checked I followed the example of the book. Like for afansari, the error disappeared also mysteriously after I added an (seemingly) unrelated instruction somewhere else. And after that it never reproduced again.
My guess is that the ListView Builder met an uninitialised List in a first round of execution, as in React, hence it met a variable with the type “null”. Me adding an instruction somewhere displaced the memory of List to a location that contained something, making the error disappear. During the rest of the execution, List is initialised with true values and the error never happened again.
Details of what happened to me:
executed steps of the tutorial code without problem until chapter 2-hello-flutter, when populating “TODO: Expanded”, “showing the ingredients”
in recipe_detail.dart, adding ListView.builder() caused the error message
hot restart and Android Studio restart still gave the same error
in main.dart, in GestureDetector, in the code block of onTap(), before Navigator.push, I inserted a print instruction of the ingredients List
the error disappeared
I removed the print instruction; no more error, never happened again.
If the error ever happen in the future, in recipe.dart I’ll try and set the List ingredients to an empty array. If it helps, it means that I guessed right.