Skip to content

Instantly share code, notes, and snippets.

@Kurogoma4D
Last active June 5, 2020 00:45
Show Gist options
  • Save Kurogoma4D/e139b4eb5ddec24fb25f17b8709427f7 to your computer and use it in GitHub Desktop.
Save Kurogoma4D/e139b4eb5ddec24fb25f17b8709427f7 to your computer and use it in GitHub Desktop.
mixin CancelableNotify on ChangeNotifier {
bool _mounted = true;
@override
void notifyListeners() {
if (_mounted) super.notifyListeners();
}
@override
void dispose() {
_mounted = false;
super.dispose();
}
}
/// Usage:
/// class PageController extends ChangeNotifier with CancelableNotify {
/// PageController() {
/// initText();
/// }
///
/// String text = '';
///
/// void initText() async {
/// await Future.delayed(const Duration(milliseconds: 4000));
/// text = 'init';
/// notifyListeners();
/// }
/// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment