Type 'Null' is not a subtype of type 'List<Ingredient>' of 'function result'

" type ‘Null’ is not a subtype of type ‘List’ of ‘function result’ "

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.

@afajansari what version of flutter are you using?

Can you please check the final project to see if you did anything differently?

actually, I did the same. I don’t know why this happened.
I try Change in the code and then undo it.
And Voila! the bug is fixed.

1 Like

haha glad you found your answer @afajansari

1 Like

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.

2 Likes

@alhajimsabu or anyone having issues when developing with flutter.

For myself I find this approach to be helpful and encourage everyone to remember and try it:

  • Hot reload or hot restart
  • Kill the app and rebuild
  • Set breakpoints to debug and understand why it’s null
  • Pulling up Flutter DevTools to help analyze the properties in the widget tree
1 Like

@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.