i am new in flutter recently i am working on a project i face to problem that i can not solve it please answer to my question my question is: i have list of products which is store in api, i fetch products from api but it has two filed in header one page and other is per_page. i want to create a pagination with my product list the pagination concept already set in api it means i have two filed page means which page i want to display and per_page how many records i want to show in one page. i simply retrieve the first page with 7 record : https://fms-dev.asrepoya.com/api/products?per_page=7&page=1
but i want to retrieve all pages with 7 records , it should create a pagination for every page for example page first 7 record, page second 7 records….. until end of records , i should click on fist page and only show me 7 records, if i click on page second 7 different records. this is my api fetch product :
Future<List<Product>> getProductList({token}) async {
final response = await http.get(
Uri.parse('$path/products?per_page=7&page=1'),
headers: header(token: token));
// print('Status code: ${response.statusCode}');
// print('Response body: ${response.body}');
if (response.statusCode == 200) {
Map<String, dynamic> jsonResponse = jsonDecode(response.body);
List<dynamic> productList = jsonResponse['data']['data'];
List<Product> products =
productList.map((item) => Product.fromJson(item)).toList();
return products;
} else {
throw Exception('Failed to load product list');
}
}e here