Skip to content

Instantly share code, notes, and snippets.

@votruk
Last active February 19, 2022 11:54
Show Gist options
  • Select an option

  • Save votruk/6b9d3933b5ee6fb00f4e388b88ac1d00 to your computer and use it in GitHub Desktop.

Select an option

Save votruk/6b9d3933b5ee6fb00f4e388b88ac1d00 to your computer and use it in GitHub Desktop.
two_level_request.dart
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