Logo

dev-resources.site

for different kinds of informations.

Mounted check in a stateless widget

Published at
1/17/2023
Categories
flutter
dart
mobile
extension
Author
Gülsen Keskin
Categories
4 categories in total
flutter
open
dart
open
mobile
open
extension
open
Mounted check in a stateless widget

If you want to use mounted check in a stateless widget its possible by making an extension on BuildContext

extension ContextExtensions on BuildContext {
  bool get mounted {
    try {
      widget;
      return true;
    } catch (e) {
      return false;
    }
  }
}

and then you can use it like this

if (context.mounted)

https://stackoverflow.com/a/74575955/14745090

Featured ones: