TickRepository class

A repository that emits ticks at a specified interval. The emitted ticks can be used to trigger periodic updates in the application.

This repository generates periodic ticks and emits them as events. It can be paused and resumed. When paused, it will not emit any ticks.

To use this repository watch it in your repository and override the build method to handle the ticks:

class MyRepository extends Repository<Value> {
  final TickRepository _tickRepository;

  MyRepository(this._tickRepository) : super(Value.new) {
    watch(_tickRepository);
  }

  @override
  FutureOr<void> build() async {
    // Refresh the state of the repository
  }
}

You also must register an instance in your Module by calling the RepositoryInjectorExt.addTickRepository method:

@override
void binds(Injector i) {
  i.addTickRepository(TickInterval(seconds: 1));
}
Inheritance
Annotations
  • @Deprecated('Use Repository.updateInterval instead')

Constructors

TickRepository(TickInterval _interval, {bool paused = false})
A repository that emits ticks at a specified interval. The emitted ticks can be used to trigger periodic updates in the application.

Properties

errorLevel Level
The level to log error messages at.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
isClosed bool
Whether the bloc is closed.
no setterinherited
level Level
The level to log messages at.
no setteroverride
namespace String
The namespace to log messages under. e.g. 'Service.Auth'
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state Tick
The current state.
no setterinherited
stream Stream<Tick>
The current stream of states.
no setterinherited
updateInterval Duration
The interval at which the repository should update. If Duration.zero, the repository will not update unless triggered by another repository. When automatic updates are enabled, the build method will be called with UpdateTrigger at the specified interval.
no setteroverride

Methods

addError(Object error, [StackTrace? stackTrace]) → void
Reports an error which triggers onError with an optional StackTrace.
inherited
build(Type trigger) FutureOr<void>
Gets called when a repository watched via watch emits a new state or when the repository is initialized (in witch case trigger is InitialBuildTrigger). Also gets called when the repository is updated (if updateInterval is not Duration.zero).
override
close() Future<void>
Closes the instance. This method should be called when the instance is no longer needed. Once close is called, the instance can no longer be used.
inherited
dispose() → void
Disposes controllers, streams, etc.
inherited
emit(Tick state) → void
Updates the state to the provided state. emit does nothing if the state being emitted is equal to the current state.
inherited
listen(void onData(Tick)?, {Function? onError, void onDone()?, bool? cancelOnError}) StreamSubscription<Tick>
Shortcut for Stream.listen.
inherited
log(Object message, [Object? error, StackTrace? stackTrace]) → void
Logs a message with an optional error and stack trace.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onChange(Change<Tick> change) → void
Called whenever a change occurs with the given change. A change occurs when a new state is emitted. onChange is called before the state of the cubit is updated. onChange is a great spot to add logging/analytics for a specific cubit.
inherited
onError(Object error, StackTrace stackTrace) → void
Called whenever an error occurs and notifies BlocObserver.onError.
inherited
pause() → void
Pauses the tick emission.
resume() → void
Resumes the tick emission.
toString() String
A string representation of this object.
inherited
watch<T>(Repository<T> repository) → void
Watches another repository for changes.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited