You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
647 B
24 lines
647 B
import 'dart:convert';
|
|
|
|
import 'package:http/http.dart';
|
|
import 'package:thesis_shop/models/product.dart';
|
|
|
|
class ProductService {
|
|
final String url;
|
|
|
|
ProductService({
|
|
this.url =
|
|
"https://gist.githubusercontent.com/jonasfranz/3ba3b1d8453d2cb3a4571e20d7bd4eca/raw/747b131c48b894873711e040ad077df201180093/products.json",
|
|
});
|
|
|
|
Future<List<Product>> fetchProducts() async {
|
|
final result = await get(Uri.parse(url));
|
|
final List<dynamic> parsed = jsonDecode(result.body);
|
|
return parsed
|
|
.map((e) => Product(
|
|
title: e['title'],
|
|
price: e['price'],
|
|
))
|
|
.toList();
|
|
}
|
|
}
|
|
|