Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Don't use 'BuildContext's across async gaps – where does the mounted property come from?

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);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s a property of the State class – which your State extends.

https://api.flutter.dev/flutter/widgets/State-class.html

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading