safeSetState method

FutureOr<void> safeSetState(
  1. FutureOr fn()
)

setState after the fn is done while the State is still mounted and State.context is safe to mark needs build.

Implementation

FutureOr<void> safeSetState(FutureOr<dynamic> Function() fn) async {
  await fn();
  if (mounted &&
      !context.debugDoingBuild &&
      context.owner?.debugBuilding != true) {
    // ignore: invalid_use_of_protected_member
    setState(() {});
  }
}