Skip to content

Instantly share code, notes, and snippets.

@incker
Created October 25, 2019 14:25
Show Gist options
  • Save incker/0bed8f761fdcf789629b1ecd783846ca to your computer and use it in GitHub Desktop.
Save incker/0bed8f761fdcf789629b1ecd783846ca to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'dart:convert';
void main() {
Future<String> queryOne() async {
return "[1,2,3]";
}
Future<String> queryTwo() async {
return "{\"test\":true}";
}
T parseJson<T>(String resp) {
const json = const JsonCodec();
try {
return json.decode(resp);
} catch (e) {
print('Some error on parsing json: $e');
return null;
}
print('Invalid resp: $resp');
return null;
}
queryOne().then(parseJson).then((Map<String, dynamic> onValue) {
return 1;
});
for (int i = 0; i < 5; i++) {
print('hello ${i + 1}');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment