Skip to content

Instantly share code, notes, and snippets.

@berkayoruc
Created December 2, 2021 10:40
Show Gist options
  • Save berkayoruc/0dd2a4989bb2c4506ed68281b4422dad to your computer and use it in GitHub Desktop.
Save berkayoruc/0dd2a4989bb2c4506ed68281b4422dad to your computer and use it in GitHub Desktop.
Future<List<Buffet>> getBuffets() async {
var headers = {'Access-Control-Allow-Origin': '*'};
final response = await http.get(Uri.parse(buffetUrl), headers: headers);
return compute(parseBuffets, [response.body]);
}
List<Buffet> parseBuffets(List<dynamic> arguments) {
final body = arguments.elementAt(0);
final parsed = jsonDecode(body)['result']['records'];
List<Buffet> values = [];
if (parsed != null) {
values = parsed
.map<Buffet>((e) => Buffet(
int.parse(e['_id'].toString()),
e['Ilce_Adi'],
e['Mahalle_Adi'],
e['Bufe_Adi'],
e['Enlem'],
e['Boylam']))
.toList();
}
return values;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment