withClock<T> function Null safety

T withClock<T>(
  1. Clock clock,
  2. T callback(
      ),
    1. {@Deprecated('This parameter is deprecated and should be avoided') bool isFinal = false}
    )

    Runs callback with the given value for the top-level clock field.

    This is Zone-scoped, so asynchronous callbacks spawned within callback will also use the new value for clock.

    If isFinal is true, calls to withClock within callback will throw a StateError. However, this parameter is deprecated and should be avoided.

    Implementation

    // ignore: deprecated_member_use_from_same_package
    /// If [isFinal] is `true`, calls to [withClock] within [callback] will throw a
    /// [StateError]. However, this parameter is deprecated and should be avoided.
    T withClock<T>(
      Clock clock,
      T Function() callback, {
      @Deprecated('This parameter is deprecated and should be avoided')
          bool isFinal = false,
    }) {
      if ((Zone.current[_isFinalKey] ?? false) == true) {
        throw StateError(
            'Cannot call withClock() within a call to withClock(isFinal = true).');
      }
    
      return runZoned(callback,
          zoneValues: {_clockKey: clock, _isFinalKey: isFinal});
    }