close method
Closes the bloc instance and performs necessary cleanup operations.
This method is called when the bloc is no longer needed. It cancels all active event subscriptions. Subclasses can override this method to provide additional cleanup logic.
It's important to call super.close()
at the end of the overridden method
to ensure proper cleanup. For example:
@override
Future<void> close() {
// Perform additional cleanup logic
myCustomResource.dispose();
// Call super.close() to complete the bloc's cleanup process
return super.close();
}
Returns a Future that completes when the cleanup process is finished.
Implementation
@override
Future<void> close() {
eventListeners.forEach((key, value) {
value.cancel();
});
return super.close();
}