Created
February 11, 2021 09:54
-
-
Save Abdulsametileri/5b2467171df6e8c752603c9493593651 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 'package:dio/dio.dart'; | |
import 'package:infinite_scroll/model/card_model.dart'; | |
import 'package:infinite_scroll/service/card_service_interface.dart'; | |
import 'package:infinite_scroll/model/pagination_model.dart'; | |
class CardService extends CardServiceInterface { | |
Dio _dio; | |
CardService() { | |
_dio = Dio(); | |
} | |
@override | |
Future<List<CardModel>> fetchCards(PaginationModel paginate) async { | |
var queryParameters = {"page": paginate.page, "limit": paginate.limit}; | |
try { | |
var response = await _dio.get( | |
'https://picsum.photos/v2/list', | |
queryParameters: queryParameters, | |
); | |
return response.data.map((e) => CardModel.fromJson(e)).toList().cast<CardModel>() as List<CardModel>; | |
} catch (e) { | |
return []; | |
} | |
} | |
} |
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 '../model/card_model.dart'; | |
import '../model/pagination_model.dart'; | |
abstract class CardServiceInterface { | |
Future<List<CardModel>> fetchCards(PaginationModel paginate); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment