Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't use 'BuildContext's across async gaps, guarded by an unrelated 'mounted' check

Tags:

flutter

dart

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);
}
like image 683
Bensal Avatar asked Sep 10 '25 17:09

Bensal


1 Answers

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

like image 137
Munsif Ali Avatar answered Sep 12 '25 14:09

Munsif Ali