Created
October 15, 2022 03:10
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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