Created
January 7, 2020 21:04
-
-
Save azamsharp/f51439a20e73ee5673189055f3962fec to your computer and use it in GitHub Desktop.
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 'package:stocks_app_flutter/models/stock.dart'; | |
import 'package:http/http.dart' as http; | |
class Webservice { | |
Future<List<Stock>> getStocks() async { | |
final url = "https://silicon-rhinoceros.glitch.me/stocks"; | |
final response = await http.get(url); | |
if (response.statusCode == 200) { | |
Iterable json = jsonDecode(response.body); | |
return json.map((stock) => Stock.fromJson(stock)).toList(); | |
} else { | |
throw Exception("Error fetching stocks"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment