Last active
June 5, 2020 00:45
-
-
Save Kurogoma4D/e139b4eb5ddec24fb25f17b8709427f7 to your computer and use it in GitHub Desktop.
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
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