Skip to content

Instantly share code, notes, and snippets.

@tentenponce
Created October 15, 2022 03:10
Show Gist options
  • Save tentenponce/8939fad6939cacf9a869d9e53c190f49 to your computer and use it in GitHub Desktop.
Save tentenponce/8939fad6939cacf9a869d9e53c190f49 to your computer and use it in GitHub Desktop.
Single event for flutter. Use to emit one time single events such as snackbars, dialogs, screen redirection, etc.
class SingleEvent<T> {
SingleEvent({required Function(T? param) invoke}) : _invoke = invoke;
final Function(T? param) _invoke;
bool _isClosed = false;
bool get isClosed => _isClosed;
void invokeWith(T? param) {
if (!_isClosed) {
_invoke(param);
}
}
void invoke() {
if (!_isClosed) {
_invoke(null);
}
}
void close() {
_isClosed = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment