CubitManager<C extends Cubit, T, I> class abstract

A CubitManager is a factory for a single Cubit type. It handles the lifecycle of the cubits of a specific type by assigning id to each instance. This is handy when you want to ensure that only one cubit of each id is used across your app. A classic use case could be managing posts cubits inside and app, with posts objects that can be edited as the app runs. CubitManager will ensure that only one cubit is associated to a specific post (given a unique post ID). While using CubitManager, you may not want the cubits to be automatically closed by widgets such as BlocProvider. Be sure to always use BlocProvider.value instead of the default constructor, as the latest internally handle the created cubit lifecycle. CubitManager needs three generic types in order to be instanced:

  • C the cubit type to manage
  • T the type of the object tracked by a cubit C
  • I the type of the unique identifier of the T object, which will be used to identify the cubits

Constructors

CubitManager.new()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(T object) → void
inserts a new object in the manager. This will initialize a new cubit bound to this object, or update the current one using updateCubit. You can obtain the binded cubit by calling get
addAll(Iterable<T> objects) → void
inserts several objects in the manager at once. See add
buildId(T object) → I
specifies how to get the unique object identifier
clear() → void
closes all cubits tracked and releases memory. Use this as a dispose method
create(T object) → C
specifies how to create a cubit from one object
get(T object) → C
returns the cubit bound to the given object. Throws an UnsupportedError if no cubit found. You should register new objects by using add before trying to get them
getById(I id) → C
returns the cubit identified by this id. Throws an UnsupportedError if no cubit found. You should register new objects by using add before trying to get them
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(T object) → void
closes the cubit bound to this object and removes it from the track list
removeAll(Iterable<T> objects) → void
removes several cubits at once. See remove
toString() String
A string representation of this object.
inherited
updateCubit(C cubit, T object) → void
When an object with the same ID as one already tracked emerged, this method is used to decide what to do. You can update the current tracked cubit or replacing it, for example

Operators

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