Skip to content

Instantly share code, notes, and snippets.

@ampersanda
Created November 13, 2020 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ampersanda/43ee0665bde93d49b445c3c907f8458a to your computer and use it in GitHub Desktop.
Save ampersanda/43ee0665bde93d49b445c3c907f8458a to your computer and use it in GitHub Desktop.
Manage single loading state of Provider's Notifier
mixin SingleLoadingStoreMixin on ChangeNotifier {
/// Loading state
bool _isLoading = false;
/// Loading getter
bool get isLoading => _isLoading;
/// Set loading state to true
void $showLoading() {
if (!_isLoading) {
_isLoading = true;
notifyListeners();
}
}
/// Set loading state to true
void $hideLoading() {
if (_isLoading) {
_isLoading = false;
notifyListeners();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment