Search code examples
flutterdartreloadflutter-web

"_debugCurrentBuildTarget == context is not true" on page reload


I get the below error whenever I refresh a page in my flutter web project

_debugCurrentBuildTarget == context is not true
at Object.throw_ [as throw] (errors.dart:216)
at Object.assertFailed (errors.dart:26)
at framework.dart:2611
at framework.BuildOwner.new.buildScope (framework.dart:2614)
at RenderObjectToWidgetAdapter.new.attachToRenderTree (binding.dart:1044)
at binding$5.WidgetsFlutterBinding.new.attachRootWidget (binding.dart:924)
at binding.dart:906
at internalCallback (isolate_helper.dart:50)

Solution

  • Finally, I got it fixed!!! I'm using cloud_firestore in my app, the userId I was trying to access in my widget tree was not yet available at the time of render. I figured this out by wrapping the root widget return statement in a trycatch block, as soon as I did this, The error stopped since its being handled and I printed the error to the console, then I returned a progress loader in the catch block.