Created
December 17, 2019 11:27
-
-
Save GIfatahTH/fb8149542bfc3bb7b1de4cc58c47d737 to your computer and use it in GitHub Desktop.
This file contains 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 FutureCounterWithError extends ChangeNotifier { | |
int _count = 0; | |
int get count => _count; | |
bool isLoaded = false; | |
bool hasError = false; | |
String errorMessage; | |
Future<void> increment() async { | |
isLoaded = false; | |
notifyListeners(); | |
await Future<void>.delayed(const Duration(seconds: 1)); | |
try { | |
if (Random().nextBool()) { | |
throw CounterError('There is a problem in your counter'); | |
} | |
isLoaded = true; | |
hasError = false; | |
_count++; | |
notifyListeners(); | |
} catch (e) { | |
hasError = true; | |
errorMessage = 'There is a problem in your counter'; | |
notifyListeners(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment