Launch Sale!

33% off all my courses

Code with Andrea Pro has launched!

View Offer

Using context.mounted in Flutter 3.7

Up until recently, it wasn't possible to check if a StatelessWidget was mounted in Flutter.

But since Flutter 3.7, BuildContext itself has a mounted property! 🎉

Since Flutter 3.7, BuildContext as a mounted property that we can check inside any widget
Since Flutter 3.7, BuildContext as a mounted property that we can check inside any widget

This makes it easy to check if any widget is mounted, just like this:

// inside any widget @override Widget build(BuildContext context) { return ElevatedButton( child: const Text('Submit'), onPressed: () async { await doSomeAsyncWork(); // a method that returns a Future if (context.mounted) { Navigator.of(context).pop(); } }, ); }

That's a great quality-of-life improvement. 👌

Note: to better understand when you should check if a widget is mounted, watch this video:

Want More?

Invest in yourself with my high-quality Flutter courses.

Flutter Foundations Course

Flutter Foundations Course

Learn about State Management, App Architecture, Navigation, Testing, and much more by building a Flutter eCommerce app on iOS, Android, and web.

Flutter & Firebase Masterclass

Flutter & Firebase Masterclass

Learn about Firebase Auth, Cloud Firestore, Cloud Functions, Stripe payments, and much more by building a full-stack eCommerce app with Flutter & Firebase.

The Complete Dart Developer Guide

The Complete Dart Developer Guide

Learn Dart Programming in depth. Includes: basic to advanced topics, exercises, and projects. Fully updated to Dart 2.15.

Flutter Animations Masterclass

Flutter Animations Masterclass

Master Flutter animations and build a completely custom habit tracking application.