How to rewrite this to awoid Don't use 'BuildContext's across async gaps.
warning.
onPressed: () async {
if (snapshot.hasData) {
final isRapportExist = await bloc.isRapportExist();
if (isRapportExist) {
return;
}
bloc.submitRapport();
Navigator.pop(context, true); //Don't use 'BuildContext's across async gaps.
}
},
In such cases usully mounted
property used, but where it comes from?
if(!mounted) return; //Undefined name 'mounted'.
Navigator.pop(context, true);
2
Answers
It’s a property of the State class – which your State extends.
https://api.flutter.dev/flutter/widgets/State-class.html
You can access it from context (
BuildContext
).