setStateAsync method

void setStateAsync(
  1. FutureOr fn(), {
  2. void onError(
    1. Object e,
    2. StackTrace stackTrace
    )?,
})

Implementation

void setStateAsync(
  FutureOr<dynamic> Function() fn, {
  void Function(Object e, StackTrace stackTrace)? onError,
}) async {
  try {
    await fn();

    if (mounted) {
      // ignore: invalid_use_of_protected_member
      setState(() {});
    }
  } catch (e, stack) {
    if (onError != null) {
      onError(e, stack);
    }
  }
}