0

I recently migrated my app to Flutter 2.0 which contains Null safety. After successful migration, when I run the app, I get the following error

The following _CastError was thrown building ContactListWidget(dirty, dependencies: [MediaQuery, _InheritedProviderScope], state: _ContactListWidgetState#9ca7f)

The error mentions no line number where the error is getting thrown, the code is approximately 500 lines :/

How do I fix this issue? Is it related to Firebase queries/data?

EDIT

I was able to locate the erroneous line, and it seems like a problem with the usage of ? and !. Can anyone direct to a resource where it is easy to understand null safety? Thanks

shangod
  • 517
  • 1
  • 4
  • 10
  • Well, if you don't get a proper error and cannot catch it with a debugger, then the only option that's left is comment out the whole build function of ContactListWidget and put it back line by line and see at which point it fails. – nvoigt Apr 12 '21 at 12:58
  • 1
    Are you sure there is no stack trace printed to the console? Can you get a stack trace if you surround the body of your `ContactListWidget.build` function with a `try`-`catch` and print it yourself? – jamesdlin Apr 12 '21 at 15:08
  • 1
    yes, found the stack trace, silly doubt, though its a matter of ? and ! which is causing the problem – shangod Apr 12 '21 at 16:50
  • Yeah, too many peope add ? and ! to get Dart to SHUDDUP, and don't realize that they are making runtime promises for those. – Randal Schwartz Apr 12 '21 at 17:17

0 Answers0