Created
November 9, 2022 16:49
-
-
Save aniekan12/0dbd27ed47d7f7ebbe2ee8f2cd6403c7 to your computer and use it in GitHub Desktop.
This file contains 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 'dart:developer' as developer; | |
import 'package:dio/dio.dart'; | |
import 'package:shopping_cart_with_bloc/core/models/shopping_home.dart'; | |
class ApiProvider { | |
final Dio _dio = Dio(); | |
static const shoppingHomeUrl = 'https://fakestoreapi.com/products'; | |
List<ShoppingHomeModel> _shoppingHome = []; | |
Future<List<ShoppingHomeModel>> getShoppingItems() async { | |
try { | |
Response response = await _dio.get(shoppingHomeUrl); | |
_shoppingHome.addAll( | |
List.from(response.data).map((e) => ShoppingHomeModel.fromJson(e))); | |
return _shoppingHome; | |
} catch (e) { | |
developer.log(e.toString()); | |
return []; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment