Skip to content

Instantly share code, notes, and snippets.

@pascencio
Last active April 23, 2020 17:11
Show Gist options
  • Save pascencio/b48aa21555776e90b2c897e93f8224dc to your computer and use it in GitHub Desktop.
Save pascencio/b48aa21555776e90b2c897e93f8224dc to your computer and use it in GitHub Desktop.
Dart Futures
import 'dart:math';
Future<String> httpGet(String url) {
int numeroDeLaSuerte = new Random().nextInt(100);
int delay = new Random().nextInt(10);
return Future.delayed(new Duration(seconds: delay),
() => "Hola tu número de la suerte es: ${numeroDeLaSuerte}");
}
void main() async {
print('Estamos a punto de pedir todos');
httpGet('https://api.nada.com/aliens')
.then((data) => print('Respuesta: ${data}'));
String data = await httpGet('https://api.nada.com/aliens');
print('Respuesta: ${data}');
print('Ultima línea');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment