NetworkCubit class abstract

A lightweight Cubit-like base class that manages NetworkState and integrates with NetworkManager.

Subclass this to create feature-specific cubits:

class UserCubit extends NetworkCubit {
  UserCubit(NetworkManager manager) : super(manager);

  Future<void> loadUser() async {
    await executeRequest(
      () => api.getUser(),
      cacheKey: 'user',
      strategy: CacheFirst(),
    );
  }
}

// Usage
final cubit = UserCubit(networkManager);
cubit.stream.listen((state) {
  switch (state) {
    case Success<User>() => print(state.data.name);
    case Loading() => print('loading...');
    // ...
  }
});
await cubit.loadUser();

Constructors

NetworkCubit(NetworkManager _manager)
Creates a NetworkCubit with the given NetworkManager.

Properties

hashCode int
The hash code for this object.
no setterinherited
isClosed bool
Whether the cubit has been closed.
no setter
manager NetworkManager
The underlying NetworkManager.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state NetworkState
The current state.
no setter
stream Stream<NetworkState>
Stream of state changes.
no setter

Methods

close() Future<void>
Close the cubit and release resources.
emit(NetworkState newState) → void
Emit a new state and notify listeners.
executeRequest<T>(Future<T> requestFn(), {String? cacheKey, NetworkStrategy? strategy, Duration? cacheTtl}) Future<T?>
Execute a request through NetworkManager and emit state transitions.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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