Skip to content

Instantly share code, notes, and snippets.

@Abdulsametileri
Created February 11, 2021 09:54
Show Gist options
  • Save Abdulsametileri/5b2467171df6e8c752603c9493593651 to your computer and use it in GitHub Desktop.
Save Abdulsametileri/5b2467171df6e8c752603c9493593651 to your computer and use it in GitHub Desktop.
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 [];
}
}
}
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