update<R extends T> method

void update<R extends T>(
  1. dynamic mutator(
    1. R s
    ), {
  2. bool shouldNotify = true,
  3. String? tag,
})

Implementation

void update<R extends T>(
  dynamic Function(R s) mutator, {
  bool shouldNotify = true,
  String? tag,
}) {
  assert(R == T,
      'Type mismatch: update<$R> called on Injected<$T>. The type parameter must match exactly (no subtype).');
  final R stateAsR = state as R;
  final result = mutator(stateAsR);
  if (result is T) {
    try {
      state = result;
    } catch (_) {}
  }
  if (shouldNotify && WidgetsBinding.instance.isRootWidgetAttached) {
    _TagRegistry.set(this, tag);
    notify();
    WidgetsBinding.instance
        .addPostFrameCallback((_) => _TagRegistry.clear(this));
  }
}