setState<R> method

R? setState<R>([
  1. R? fn()?
])

Rebuild all dependent widgets.

Implementation

R? setState<R>([R? Function()? fn]) {
  if (!didWrap) {
    throw FlutterError.fromParts([
      ErrorSummary("SharedValue was not initalized."),
      ErrorHint(
        "Did you forget to call SharedValue.wrapApp()?\n"
        "If so, please do it once,"
        "alongside runApp() so that SharedValue can be initalized for you application.\n"
        "Example:\n"
        "\trunApp(SharedValue.wrapApp(MyApp()))",
      )
    ]);
  }

  R? ret = fn?.call();

  if (ret is Future) {
    ret.then((_) {
      _update();
    });
  } else {
    _update();
  }

  return ret;
}