Last active
February 19, 2022 11:54
-
-
Save votruk/6b9d3933b5ee6fb00f4e388b88ac1d00 to your computer and use it in GitHub Desktop.
two_level_request.dart
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
| import 'dart:math'; | |
| void main() { | |
| final superhero = Random().nextBool() ? "Superhero" : null; | |
| if (superhero != null) { | |
| print("Получили супергероя из избранного"); | |
| changeState("Success"); | |
| } else { | |
| print("В избранном нет супергероя"); | |
| changeState("Loading"); | |
| } | |
| request(); | |
| } | |
| void changeState(final String state) { | |
| print("НОВОЕ СОСТОЯНИЕ: $state"); | |
| } | |
| void request() { | |
| final serverResponse = makeRequestOnServer(); | |
| if (serverResponse == "Superhero") { | |
| changeState("Success"); | |
| } else { | |
| changeState("Error"); | |
| } | |
| } | |
| String? makeRequestOnServer() { | |
| final serverResponseSuccess = Random().nextBool(); | |
| if (serverResponseSuccess) { | |
| print("Сервер вернул обновленную модель Супрегероя"); | |
| return "Superhero"; | |
| } else { | |
| print("Запрос к серверу окончился ошибкой"); | |
| return "Request Error"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment