skip to Main Content

Why is the error saying "Don't use 'BuildContext's across async gaps, guarded by an unrelated 'mounted' check."? Is the mounted getter deprecated?

if (context.mounted) {
  pop(context);
}

2

Answers


  1. Now in newer version of flutter you can use mounted directly inside StatefulWidget

    instead of using

    if (context.mounted) {
      pop(context);
    }
    

    Use

    if (mounted) {
      pop(context);
    }
    

    you can check the details when to use context.mounted and mounted here: use_build_context_synchronously

    Login or Signup to reply.
  2. whenever you need to pass context, try to bind it inside this condition,

    if(mounted)
    {
      //your code where context need to be passed
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search