Home > Mobile >  Navigator error with context what is the reason for the announcement,
Navigator error with context what is the reason for the announcement,

Time:12-27

enter image description here

error text: Do not use BuildContexts across async gaps.dartuse_build_context_synchronously

I don't understand the reason for the announcement

CodePudding user response:

In stateFulWidget when you use async - await you have to confirm that next widgets are mounted in Navigation.

So for that you have to add condition for mounted widget

 if (!mounted) return;
 Navigator.push(
      context,
      MaterialPageRoute(
      builder: (context) => ElectionInfo(),
 ));
  • Related