Dio API Integration with Pagination in Flutter
Learn how to integrate Dio (HTTP client) with API calls and implement pagination efficiently in a Flutter app.
Explore sample code, step-by-step tutorials, and best practices for seamless API integration with pagination.
dependencies:
flutter:
sdk: flutter
dio: ^5.3.0
provider: ^6.0.5
main.dart : The main entry point of the Flutter app.
// main.dart
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutteryfly/viewmodels/grid_photo_provider.dart';
import 'package:flutteryfly/views/pagination2.dart';
import 'package:provider/provider.dart';
import './data/services/api_service.dart';
import 'data/repositories/pagination_repository.dart';
void main() {
// Create Dio instance for HTTP requests
final Dio dio = Dio();
// Create ApiService instance with the Dio instance
final ApiService apiService = ApiService(dio: dio);
// Create PaginationRepository instance with the ApiService instance
final paginationRepository = PaginationRepository(apiService: apiService);
// Provider
runApp(
MultiProvider(
providers: [
// Provide the LoginViewModel with LoginViewModel dependency to manage user data and API calls
ChangeNotifierProvider<PhotoProvider>(
create: (context) => PhotoProvider(userRepository: paginationRepository),
),
],
child: const MyApp(),
),
);
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Pagination', // Meta Title for the App
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const PaginationViewWidget(),
);
}
}
..
pagination_demo.dart :To build a list view page.
// view/pagination_demo.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../viewmodels/grid_photo_provider.dart';
class PaginationViewWidget extends StatefulWidget {
const PaginationViewWidget({Key? key}) : super(key: key);
@override
PaginationViewWidgetState createState() => PaginationViewWidgetState();
}
class PaginationViewWidgetState extends State<PaginationViewWidget> {
late PhotoProvider _photoProvider;
bool _isLoadingMore = false;
final ScrollController _scrollController = ScrollController();
@override
void initState() {
super.initState();
// Initialize the PhotoProvider
_photoProvider = Provider.of<PhotoProvider>(context, listen: false);
_loadMoreData();
// Listen to the scroll position and check when the user reaches the bottom of the list
_scrollController.addListener(() {
if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent) {
_loadMoreData();
}
});
}
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
void _loadMoreData() async {
if (!_isLoadingMore) {
setState(() {
_isLoadingMore = true;
});
// Call the API to load more data
await _photoProvider.callPhotoApi();
setState(() {
_isLoadingMore = false;
});
}
}
@override
Widget build(BuildContext context) {
if (kDebugMode) {
print('Building...');
}
return Scaffold(
appBar: AppBar(
title: const Text('My ListView'),
),
body: Stack(
children: [
Consumer<PhotoProvider>( // Consumer widget to listen for changes in UserViewModel
builder: (BuildContext context, PhotoProvider photoProvider, _) {
return ListView.builder(
controller: _scrollController,
itemCount: photoProvider.photos.length + 1,
itemBuilder: (context, index) {
if (index == photoProvider.photos.length) {
if (kDebugMode) {
print('Loading more...');
}
return photoProvider.isLoading
? const Center(
child: CircularProgressIndicator(),
)
: Container(); // Return an empty container to hide the "Load More" button when all data is loaded
} else {
final photo = photoProvider.photos[index];
return Card(
margin: const EdgeInsets.all(15), // Set your desired margin value
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
clipBehavior: Clip.antiAliasWithSaveLayer,
elevation: 10,
shadowColor: Colors.yellow, // Set your desired shadow color here
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
Image.network(
photo.webformatURL.toString(),
height: 340,
width: double.infinity,
fit: BoxFit.cover,
),
Container(
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.transparent, Colors.black.withOpacity(0.8)],
),
),
padding: const EdgeInsets.all(12),
child: const Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
"ID: ABC123",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w300,
color: Colors.white,
),
),
SizedBox(height: 4),
Text(
"Bolt UIX",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
SizedBox(height: 8),
Text(
"Age: 30 • Height: 5'9'' • City: New York • Job: App Engineer",
style: TextStyle(
fontSize: 16,
color: Colors.white,
),
),
],
),
),
Positioned(
top: 12,
right: 12,
child: Container(
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Colors.transparent,
),
child: IconButton(
icon: const Icon(Icons.more_vert),
onPressed: () {
// Handle button press
},
color: Colors.white,
),
),
),
],
),
);
}
},
);
},
),
],
),
);
}
}
..
pagination_view_model.dart : ViewModel class for managing user data and API calls.
// viewmodels/pagination_view_model.dart
import 'package:flutter/material.dart';
import '../data/models/pixelpay_photo.dart';
import '../data/repositories/pagination_repository.dart';
class PhotoProvider extends ChangeNotifier {
final PaginationRepository userRepository;
PhotoProvider({required this.userRepository});
int _page = 1; // Initial page number for pagination
String _search = 'nature'; // Initial search term for photos
List<Hits> _photos = <Hits>[]; // List to store the fetched photos
bool _isLoading = false; // Declare _isLoading as a private boolean variable
String get search => _search; // Getter for the search term
bool get isLoading => _isLoading; // Getter for the loading state
set search(String value) {
_search = value; // Setter for the search term
notifyListeners();
}
int get page => _page; // Getter for the current page number
set page(int value) {
_page = value; // Setter for the current page number
notifyListeners();
}
List<Hits> get photos => _photos; // Getter for the list of photos
set photos(List<Hits> value) {
_photos = value; // Setter for the list of photos
notifyListeners();
}
Future<void> callPhotoApi() async {
if (_isLoading) {
return; // Return if a fetch request is already in progress
}
_isLoading = true; // Set _isLoading to true before making the API call
userRepository.getPhotos(_search, _page).then((response) {
_page = _page + 1; // Increment the page number for the next fetch
addPhotosToList(PixelPay.fromJson(response).hits!); // Add fetched photos to the list
});
}
void addPhotosToList(List<Hits> photoData) {
/*_photos.addAll(photoData);
_isLoading = false; // Set _isLoading to false after the data has been fetched
notifyListeners();*/
// Simulate delay of 3 seconds to show loading state
Future.delayed(const Duration(seconds: 3), () {
_photos.addAll(photoData); // Add fetched photos to the existing list
_isLoading = false; // Set _isLoading to false after the data has been fetched
notifyListeners();
});
}
}
..
pagination_repository.dart : Handles fetching user data from the API.
// data/repositories/pagination_repository.dart
import '../services/api_service.dart';
class PaginationRepository {
final ApiService apiService; // Instance of the ApiService class to perform API requests.
PaginationRepository({required this.apiService});
Future<Map<String, dynamic>> getPhotos(String query, int page) async {
try {
// Call the ApiService's getPhotos method to fetch photos from the API
return await apiService.getPhotos(page, query);
} catch (e) {
// If an exception occurs during the API call, throw an exception with an error message.
throw Exception('Failed to fetch products');
}
}
}
..
api_service.dart : Provides methods to interact with the API using Dio or other HTTP clients.
// data/services/api_service.dart
import 'package:dio/dio.dart';
import '../../utils/logger_interceptor.dart';
class ApiService {
late Dio _dio; // Dio instance to perform HTTP requests.
// ApiService({required Dio dio}) : _dio = dio;
ApiService({required Dio dio}) {
_dio = Dio(BaseOptions(
//baseUrl: "https://dummyjson.com/products/",
// connectTimeout: const Duration(seconds:5),
// receiveTimeout: const Duration(seconds: 3),
responseType: ResponseType.json,
))..interceptors.addAll([
// LoggerInterceptor(), //custom logger interceptor.
]);
}
Future<Map<String, dynamic>> getPhotos(int page, String search) async {
try {
// Make a GET request to the API endpoint to fetch product data.
final response = await _dio.get("https://pixabay.com/api/?key=35457470-ba2fadec934c3233f2e9afacc&q=$search&image_type=photo&pretty=true&page=$page");
// Check if the response status code is 200 (OK).
if (response.statusCode == 200) {
return response.data; // If successful, return the response data (Map of dynamic).
} else {
// If the response status code is not 200, throw an exception with an error message.
throw Exception('API failed with status code: ${response.statusCode}');
}
} catch (e) {
// If any exception occurs during the API call, throw an exception with the error message.
throw Exception('An error occurred: $e');
}
}
}
..
..
https://pixabay.com/api/?key=35457470-ba2fadec934c3233f2e9afacc&q=yellow+flowers&image_type=photo&pretty=true&page=1
{
"total": 34935,
"totalHits": 500,
"hits": [
{
"id": 2295434,
"pageURL": "https://pixabay.com/photos/spring-bird-bird-tit-spring-blue-2295434/",
"type": "photo",
"tags": "spring bird, bird, tit",
"previewURL": "https://cdn.pixabay.com/photo/2017/05/08/13/15/spring-bird-2295434_150.jpg",
"previewWidth": 150,
"previewHeight": 99,
"webformatURL": "https://pixabay.com/get/g7d1c3a4d35e4c49920ae6eb23cb89a28104914f05a3e1893a5147a31523f35dabeb73bf8849169763bba513fecf57e57446b6c7306909213e4787adddb722da8_640.jpg",
"webformatWidth": 640,
"webformatHeight": 426,
"largeImageURL": "https://pixabay.com/get/gd4521f879e049a042ef87b05058c93954b65e25492efd002785d044d328f22b9daec977a05af7e00e47f9953fc94ce1f21a84cd922f7a4c83b91ed0775333633_1280.jpg",
"imageWidth": 5363,
"imageHeight": 3575,
"imageSize": 2938651,
"views": 797751,
"downloads": 474980,
"collections": 2268,
"likes": 2173,
"comments": 284,
"user_id": 334088,
"user": "JillWellington",
"userImageURL": "https://cdn.pixabay.com/user/2018/06/27/01-23-02-27_250x250.jpg"
},
{
"id": 3063284,
"pageURL": "https://pixabay.com/photos/rose-flower-petal-floral-noble-3063284/",
"type": "photo",
"tags": "rose, flower, petal",
"previewURL": "https://cdn.pixabay.com/photo/2018/01/05/16/24/rose-3063284_150.jpg",
"previewWidth": 150,
"previewHeight": 99,
"webformatURL": "https://pixabay.com/get/g077506aebf5ccbd9bbda48dab48c5a01611900f6e13a8dbf244d29a1ba6451eeb3834fb54a4dfa45b1ec03e80014d3bef6cb341880eb5b14677d5e1ff345659d_640.jpg",
"webformatWidth": 640,
"webformatHeight": 426,
"largeImageURL": "https://pixabay.com/get/gce57e572ff6c426dab63555bbbef8c8e66016135d6d875868943c0ef05ba9040c25aa415fb2af4108418ad840045673de83225952e359fcbd78eb2149b637ca3_1280.jpg",
"imageWidth": 6000,
"imageHeight": 4000,
"imageSize": 3574625,
"views": 1127203,
"downloads": 733720,
"collections": 1497,
"likes": 1623,
"comments": 338,
"user_id": 1564471,
"user": "anncapictures",
"userImageURL": "https://cdn.pixabay.com/user/2015/11/27/06-58-54-609_250x250.jpg"
},
]
}
// data/model/pixelpay_photo.dart
/// total : 31863
/// totalHits : 500
/// hits : [{"id":736877,"pageURL":"https://pixabay.com/photos/tree-cat-silhouette-moon-full-moon-736877/","type":"photo","tags":"tree, cat, silhouette","previewURL":"https://cdn.pixabay.com/photo/2015/04/23/21/59/tree-736877_150.jpg","previewWidth":150,"previewHeight":100,"webformatURL":"https://pixabay.com/get/g23c3d97a250a9c49efe3f9674a48fba61eebb42437052a35a60e544222813c6d651756a4de177551ad6817a808ba2d71_640.jpg","webformatWidth":640,"webformatHeight":427,"largeImageURL":"https://pixabay.com/get/g972529be72e7aeef825712744208e233f6ae4c5454e9dfa3522218a96b4b0b4c57c04a6d73edb6bdc184ca8f3df8ac1d2e88fce954e5ee336019793819e61fbb_1280.jpg","imageWidth":1920,"imageHeight":1282,"imageSize":97150,"views":1244651,"downloads":631783,"collections":2355,"likes":2844,"comments":573,"user_id":909086,"user":"Bessi","userImageURL":"https://cdn.pixabay.com/user/2019/04/11/22-45-05-994_250x250.jpg"},{"id":2083492,"pageURL":"https://pixabay.com/photos/cat-young-animal-kitten-gray-cat-2083492/","type":"photo","tags":"cat, young animal, kitten","previewURL":"https://cdn.pixabay.com/photo/2017/02/20/18/03/cat-2083492_150.jpg","previewWidth":150,"previewHeight":91,"webformatURL":"https://pixabay.com/get/g716e7aa9aac007fcf0b2b6c212c576b4b35d681545afc81de0c59c578879cd60c4edb81265e98e646ab92ea639994cdcc5f235acc2a44e4c25fe74e76f844dfc_640.jpg","webformatWidth":640,"webformatHeight":390,"largeImageURL":"https://pixabay.com/get/g60289f3d15ce797d92657ce938494401a37103ddbb8c270fd7b3672e8687ef298eb0ac49835202fd0b16f226f4104459b41d25f15e4099c1a0eec76f95947693_1280.jpg","imageWidth":4928,"imageHeight":3008,"imageSize":4130948,"views":1200930,"downloads":697816,"collections":2104,"likes":2351,"comments":380,"user_id":1777190,"user":"susannp4","userImageURL":"https://cdn.pixabay.com/user/2015/12/16/17-56-55-832_250x250.jpg"},{"id":551554,"pageURL":"https://pixabay.com/photos/cat-kitten-pet-kitty-young-cat-551554/","type":"photo","tags":"cat, kitten, pet","previewURL":"https://cdn.pixabay.com/photo/2014/11/30/14/11/cat-551554_150.jpg","previewWidth":144,"previewHeight":150,"webformatURL":"https://pixabay.com/get/ge696e2e5839134983312fc3f46cc5aa9556303c4c17115ed414c2ff9917a32487d2827199a3d9b054b8d9222cddcb658_640.jpg","webformatWidth":613,"webformatHeight":640,"largeImageURL":"https://pixabay.com/get/g67ad6eef303a8e71c928d3434bc18083d2a93e7c86885c414bc055fd62826498a4cc2b0024a68ee35552a8be3a95b70ee629e94bcc13342c30bb2d0abe77ef36_1280.jpg","imageWidth":2392,"imageHeight":2500,"imageSize":945751,"views":1270498,"downloads":675871,"collections":1722,"likes":2325,"comments":458,"user_id":617282,"user":"Ty_Swartz","userImageURL":"https://cdn.pixabay.com/user/2014/11/30/13-45-12-52_250x250.jpg"},{"id":1285634,"pageURL":"https://pixabay.com/photos/cat-cat-s-eyes-blue-eyes-gray-cat-1285634/","type":"photo","tags":"cat, cat's eyes, blue eyes","previewURL":"https://cdn.pixabay.com/photo/2016/03/28/12/35/cat-1285634_150.png","previewWidth":150,"previewHeight":94,"webformatURL":"https://pixabay.com/get/gdb17d0c0a38daefb755eef4e0130c45bb7a3f908450b2797c9659f0bbb3dc52ad2cc2b0c0ffd208140c5b6ff47b52a11349bf2fd614dd2ba008f67f532b9d598_640.png","webformatWidth":640,"webformatHeight":402,"largeImageURL":"https://pixabay.com/get/gb882a9a4ae40b0b51d3a5a6b2edcb63939efc711cc182d19540d9fad55528bd9ee048c6773a2cc943b36f5100d4dcbf3495b3ceb9edeb73cd1262463300fc237_1280.png","imageWidth":3677,"imageHeight":2310,"imageSize":11720209,"views":950515,"downloads":483240,"collections":1653,"likes":1726,"comments":253,"user_id":127419,"user":"cocoparisienne","userImageURL":"https://cdn.pixabay.com/user/2022/12/15/08-11-57-201_250x250.jpg"},{"id":1045782,"pageURL":"https://pixabay.com/photos/cat-animal-cat-portrait-cat-s-eyes-1045782/","type":"photo","tags":"cat, animal, cat portrait","previewURL":"https://cdn.pixabay.com/photo/2015/11/16/14/43/cat-1045782_150.jpg","previewWidth":150,"previewHeight":102,"webformatURL":"https://pixabay.com/get/ge40c1dae13767c589741dbabb7315e23cea656d2115a1a40f5cfacd2011e8a28df58d4c3cae7d26ecf3f3c649b2ecdc5ec475883638ba07638fafa12697898f2_640.jpg","webformatWidth":640,"webformatHeight":437,"largeImageURL":"https://pixabay.com/get/g5df89ad4a4c33be1447f4067020d923790747bec8533e84d3fb3a723deb63059ff8305ffc581fe5490a97e2a03539912aabbd9c83f2d2d74b3160eab72bc39d6_1280.jpg","imageWidth":2064,"imageHeight":1410,"imageSize":1268850,"views":667915,"downloads":386486,"collections":1444,"likes":1698,"comments":306,"user_id":127419,"user":"cocoparisienne","userImageURL":"https://cdn.pixabay.com/user/2022/12/15/08-11-57-201_250x250.jpg"},{"id":694730,"pageURL":"https://pixabay.com/photos/maine-coon-cat-cat-s-eyes-black-cat-694730/","type":"photo","tags":"maine coon, cat, cat's eyes","previewURL":"https://cdn.pixabay.com/photo/2015/03/27/13/16/maine-coon-694730_150.jpg","previewWidth":150,"previewHeight":99,"webformatURL":"https://pixabay.com/get/g7e5707ff095dba0bfba81cd31f9e8f5e7f978d46931b08ba9fff7c6ec595f74d88b58b6a275842e3307e83024f7f78a1_640.jpg","webformatWidth":640,"webformatHeight":426,"largeImageURL":"https://pixabay.com/get/gfbf93fa6e6d9536251735326e13804c24893608bb372790c6d5c59a820e5b69a248aecf168cc4927acbb1291ad342c20520faa2750e55a3f477b570ec38000e9_1280.jpg","imageWidth":3235,"imageHeight":2157,"imageSize":546452,"views":665554,"downloads":392793,"collections":1387,"likes":1595,"comments":227,"user_id":887962,"user":"ClaudiaWollesen","userImageURL":"https://cdn.pixabay.com/user/2019/12/22/16-48-03-254_250x250.jpg"},{"id":323262,"pageURL":"https://pixabay.com/photos/cat-pet-licking-animal-tabby-cat-323262/","type":"photo","tags":"cat, pet, licking","previewURL":"https://cdn.pixabay.com/photo/2014/04/13/20/49/cat-323262_150.jpg","previewWidth":150,"previewHeight":99,"webformatURL":"https://pixabay.com/get/gdc74ca64557c1bbd33650bfe332f49f6bbccfa9c81f0073527b9c9a80099aec0c70b2bf897693df4eed851a0531ff171_640.jpg","webformatWidth":640,"webformatHeight":426,"largeImageURL":"https://pixabay.com/get/g96bf4ac36d2eb7762b42fe534b265e00e64aa0ca4988df7dbfb94fccebaa957445e7748258f3fb4ea49399a4b5555b3d65b94cb866484dedd2613093b78f9e29_1280.jpg","imageWidth":2557,"imageHeight":1704,"imageSize":668468,"views":770695,"downloads":375041,"collections":1273,"likes":1572,"comments":306,"user_id":222368,"user":"TeamK","userImageURL":"https://cdn.pixabay.com/user/2020/11/21/08-20-58-568_250x250.jpg"},{"id":2536662,"pageURL":"https://pixabay.com/photos/cat-flower-kitten-stone-pet-2536662/","type":"photo","tags":"cat, flower, kitten","previewURL":"https://cdn.pixabay.com/photo/2017/07/25/01/22/cat-2536662_150.jpg","previewWidth":150,"previewHeight":99,"webformatURL":"https://pixabay.com/get/g74d8e52defb2cde6d52e3c7680120ce3360e5204da77c52138a8fa43469468017e51506a08090fb89d166f0ccb72c074120332bf71a8b72969d2d6567f71c5b8_640.jpg","webformatWidth":640,"webformatHeight":425,"largeImageURL":"https://pixabay.com/get/g9a561d8a07b02d4c01f209e339be84ec7ea226fede39a1eb3b62e9d54772a5254554c2e34a3e96f6daa57985a219e1bbb34376108288e85c1104ba9303bfe6f3_1280.jpg","imageWidth":4592,"imageHeight":3056,"imageSize":3178484,"views":902100,"downloads":544378,"collections":1547,"likes":1901,"comments":334,"user_id":5987327,"user":"Dimhou","userImageURL":"https://cdn.pixabay.com/user/2021/03/13/05-49-15-380_250x250.jpeg"},{"id":114782,"pageURL":"https://pixabay.com/photos/cat-pet-licking-animal-tabby-cat-114782/","type":"photo","tags":"cat, pet, licking","previewURL":"https://cdn.pixabay.com/photo/2013/05/30/18/21/cat-114782_150.jpg","previewWidth":114,"previewHeight":150,"webformatURL":"https://pixabay.com/get/g225d394a793ac7f40135dbb40a278e69432814735d8b23a1124c6f682c095257c31f5075d259c85c5cf61e7a90d5eaf4_640.jpg","webformatWidth":489,"webformatHeight":640,"largeImageURL":"https://pixabay.com/get/gb44cc7fec357cf5d42190c81585a66a9b1023debe5aceedff10fec84855b957e644fc5469328cabdb87e1e0df0a9a5087c77ebba6553c92856d8189dda3fd0b2_1280.jpg","imageWidth":2303,"imageHeight":3012,"imageSize":2261690,"views":501884,"downloads":286153,"collections":1185,"likes":1227,"comments":245,"user_id":5337,"user":"ArtTower","userImageURL":"https://cdn.pixabay.com/user/2019/07/27/00-12-46-447_250x250.jpg"},{"id":2934720,"pageURL":"https://pixabay.com/photos/cat-kitten-pets-animals-housecat-2934720/","type":"photo","tags":"cat, kitten, pets","previewURL":"https://cdn.pixabay.com/photo/2017/11/09/21/41/cat-2934720_150.jpg","previewWidth":150,"previewHeight":99,"webformatURL":"https://pixabay.com/get/g90015cd317b1dbd9ea3a1de484f6f3216bc671f603d12cd159791e92c23c08fd1c666739f4f90cdc89275476dea7cbdf3c5b8da29399317ba684ffb28fe3d503_640.jpg","webformatWidth":640,"webformatHeight":426,"largeImageURL":"https://pixabay.com/get/g8ec6c6b1c9d1fbeceea93ff055dac9b1028f1cd17adf7c475698ced607cc6c32d9e0430bf36d2edd65e8b3d27309dbc1c7ca5e824a6540c9ec2e3eaff840c64e_1280.jpg","imageWidth":3495,"imageHeight":2330,"imageSize":1971228,"views":538161,"downloads":315169,"collections":1124,"likes":1309,"comments":232,"user_id":6995361,"user":"Kirgiz03","userImageURL":"https://cdn.pixabay.com/user/2017/11/14/22-33-33-341_250x250.jpg"},{"id":2948404,"pageURL":"https://pixabay.com/photos/kitty-playful-flowers-wildflowers-2948404/","type":"photo","tags":"kitty, playful, flowers","previewURL":"https://cdn.pixabay.com/photo/2017/11/14/13/06/kitty-2948404_150.jpg","previewWidth":150,"previewHeight":101,"webformatURL":"https://pixabay.com/get/gf4d483f22ac24543634f09831551ef78982a18cd5d05ca16ded8dbe1042e16c6b60d22dfba056bae881328200c1af99099d9a6698163bf8475884ed928606184_640.jpg","webformatWidth":640,"webformatHeight":433,"largeImageURL":"https://pixabay.com/get/g965cacd9b6dc81203d42ee9d17221271b4952514e99484fc6ffdf0707a5025f640b3429e11297beb49aa9c12c1f3b4c694b09ba8207494f3859c0d87f6daa863_1280.jpg","imageWidth":4056,"imageHeight":2746,"imageSize":3464997,"views":642843,"downloads":415430,"collections":881,"likes":1169,"comments":162,"user_id":3558510,"user":"IlonaBurschl","userImageURL":"https://cdn.pixabay.com/user/2022/05/30/08-07-40-119_250x250.jpg"},{"id":1508613,"pageURL":"https://pixabay.com/photos/cat-tabby-face-whiskers-pet-1508613/","type":"photo","tags":"cat, tabby, face","previewURL":"https://cdn.pixabay.com/photo/2016/07/10/21/47/cat-1508613_150.jpg","previewWidth":150,"previewHeight":110,"webformatURL":"https://pixabay.com/get/g02582efc93f87f99e47a0b0510c0784f17efc22dcc27449c7aec1ad4abb4579cd5bfe40adcddc4f1dca4f738aaf925c014162a35ad607a2f5bbd05770531178b_640.jpg","webformatWidth":640,"webformatHeight":472,"largeImageURL":"https://pixabay.com/get/g1bfef76607abadd4d0f8b060c16b93e83160259836ee72fb2bbaff367d997e58d5e466fba4e022e1f1ef0e84a74628bb184af95b73812ee1b75789bbe435bdb7_1280.jpg","imageWidth":2894,"imageHeight":2135,"imageSize":1630104,"views":346923,"downloads":213710,"collections":970,"likes":985,"comments":135,"user_id":127419,"user":"cocoparisienne","userImageURL":"https://cdn.pixabay.com/user/2022/12/15/08-11-57-201_250x250.jpg"},{"id":1192026,"pageURL":"https://pixabay.com/photos/cat-kitten-pet-striped-young-1192026/","type":"photo","tags":"cat, kitten, pet","previewURL":"https://cdn.pixabay.com/photo/2016/02/10/16/37/cat-1192026_150.jpg","previewWidth":150,"previewHeight":112,"webformatURL":"https://pixabay.com/get/gc17c749a8dedb8b6692efef92d66acefc6988e5702d1a1027b5a553727c74e0a3b40422ba6ed5c9e808539c0a01079c6f9ff789fd75a65612f581b74faf0f35a_640.jpg","webformatWidth":640,"webformatHeight":480,"largeImageURL":"https://pixabay.com/get/g96f0ded2ae1013c04d9289553b078e0b0af7f689b0e6547bd44c402657d10796b4d35e2de190d91b462ba91880b0051a148a62f5ece924c2d42b51d031d86ffa_1280.jpg","imageWidth":2560,"imageHeight":1920,"imageSize":909777,"views":429812,"downloads":251245,"collections":859,"likes":898,"comments":132,"user_id":1892688,"user":"Chiemsee2016","userImageURL":"https://cdn.pixabay.com/user/2022/05/10/07-03-44-588_250x250.jpg"},{"id":3077180,"pageURL":"https://pixabay.com/illustrations/woman-cat-pet-girl-animal-3077180/","type":"illustration","tags":"woman, cat, pet","previewURL":"https://cdn.pixabay.com/photo/2018/01/11/23/16/woman-3077180_150.jpg","previewWidth":150,"previewHeight":150,"webformatURL":"https://pixabay.com/get/g2fb9c017dde05738e8846c74c44a94b4b507aa15b9baf95e85716e3413ead56bc525ca63e31fdb68fd2a23b615ec260457f65aacfa372158323b679496628651_640.jpg","webformatWidth":640,"webformatHeight":640,"largeImageURL":"https://pixabay.com/get/g6e570d142b7c8e4731923dd2b1060a2aaf18159d5d818616547e68e2a18dde3c719889323a1e951ea9ff0ceef86a6ca418876a88b333c039981ab63b6f695c8f_1280.jpg","imageWidth":2048,"imageHeight":2048,"imageSize":764933,"views":106034,"downloads":54004,"collections":1076,"likes":732,"comments":84,"user_id":3612927,"user":"freeillustrated","userImageURL":"https://cdn.pixabay.com/user/2022/07/28/11-30-06-898_250x250.jpg"},{"id":4611189,"pageURL":"https://pixabay.com/photos/kitten-cat-pet-feline-animal-fur-4611189/","type":"photo","tags":"kitten, cat, pet","previewURL":"https://cdn.pixabay.com/photo/2019/11/08/11/56/kitten-4611189_150.jpg","previewWidth":150,"previewHeight":99,"webformatURL":"https://pixabay.com/get/g2af317b324e7a0cb4092832ad1d6fa1cb4fa9173408d2309d88dbe74bdfd58bc6cefb4f76c876222e8df2add4d773050e2d5f76a8207b125a105d821bcffe287_640.jpg","webformatWidth":640,"webformatHeight":426,"largeImageURL":"https://pixabay.com/get/g8d16661e1a6055bacd9855dc959ed89216542653cdb63a7b376950b63577833e009402a4ff34b43cc2ded7d2a4fbf81d29f2d08c4016422315e5b7a188b0900b_1280.jpg","imageWidth":6000,"imageHeight":4000,"imageSize":3885974,"views":396592,"downloads":295420,"collections":822,"likes":912,"comments":175,"user_id":9285194,"user":"guvo59","userImageURL":"https://cdn.pixabay.com/user/2023/02/24/17-20-38-197_250x250.jpg"},{"id":2535888,"pageURL":"https://pixabay.com/photos/tiger-swamp-big-cat-wild-cat-2535888/","type":"photo","tags":"tiger, swamp, big cat","previewURL":"https://cdn.pixabay.com/photo/2017/07/24/19/57/tiger-2535888_150.jpg","previewWidth":150,"previewHeight":99,"webformatURL":"https://pixabay.com/get/gdf4e07590a45c472fe3e5184dfc7d9c97d51f595e08562e225181dc5745fe14653bf095c55bf61f76ce2ab286fa8135a3e3537f39a0f00cc5c24236548fab0fd_640.jpg","webformatWidth":640,"webformatHeight":426,"largeImageURL":"https://pixabay.com/get/g09901d0d4ee9b580ab0fc7e2f5a18ec52668d245b6ccdcbc85913cef695b729956325d35abdceafff386552c5f394d546431f0e346125ea092e7c529f6b5d24f_1280.jpg","imageWidth":2813,"imageHeight":1875,"imageSize":2463393,"views":800070,"downloads":533347,"collections":1676,"likes":1693,"comments":217,"user_id":2748383,"user":"andibreit","userImageURL":"https://cdn.pixabay.com/user/2016/06/19/12-23-14-902_250x250.jpg"},{"id":1647775,"pageURL":"https://pixabay.com/photos/cat-kitten-tree-curious-tabby-1647775/","type":"photo","tags":"cat, kitten, tree","previewURL":"https://cdn.pixabay.com/photo/2016/09/05/21/37/cat-1647775_150.jpg","previewWidth":150,"previewHeight":99,"webformatURL":"https://pixabay.com/get/g00cb14f7cbc52b62033901227c70aacbfbaddf605f497e9d5adf9331c727bc212025dc2fe47b51622534ce29fcd72f7b13d36498f7be5e533598ff28f668d6a5_640.jpg","webformatWidth":640,"webformatHeight":426,"largeImageURL":"https://pixabay.com/get/g12c0b019057a51e99f1675e1fb4d5acd952f4e764ba29a286d39a465162080597243323e3d0e322b126d29dd24089011068e4f1baf1a2b828835bf882772be3c_1280.jpg","imageWidth":4800,"imageHeight":3200,"imageSize":2329880,"views":316066,"downloads":204848,"collections":765,"likes":872,"comments":107,"user_id":778429,"user":"Kessa","userImageURL":""},{"id":1455468,"pageURL":"https://pixabay.com/photos/cat-face-eyes-portrait-1455468/","type":"photo","tags":"cat, face, eyes","previewURL":"https://cdn.pixabay.com/photo/2016/06/14/00/14/cat-1455468_150.jpg","previewWidth":150,"previewHeight":99,"webformatURL":"https://pixabay.com/get/gd9895edfce28226fe124e535ab7ecf8c52da9f3a1f052b2a85556f162d68dbe567ae75ed1c3371ae2d5091d97fe19fdef4d57520d1ec3f2059c95691cf770540_640.jpg","webformatWidth":640,"webformatHeight":425,"largeImageURL":"https://pixabay.com/get/gbc526dc60f86ae21d49f8d1bc54198c90da8c4f336c7f86d855417617dd2a73faf72839df1f3e6d1b9033c0c27af5e8f04d1e27f90eb35bb9a13d98926366877_1280.jpg","imageWidth":6016,"imageHeight":4000,"imageSize":9775105,"views":281682,"downloads":194529,"collections":858,"likes":792,"comments":98,"user_id":686414,"user":"Alexas_Fotos","userImageURL":"https://cdn.pixabay.com/user/2022/07/05/23-09-40-265_250x250.jpg"},{"id":1651945,"pageURL":"https://pixabay.com/photos/pile-animals-fairy-tale-1651945/","type":"photo","tags":"pile, animals, fairy tale","previewURL":"https://cdn.pixabay.com/photo/2016/09/07/16/19/pile-1651945_150.jpg","previewWidth":107,"previewHeight":150,"webformatURL":"https://pixabay.com/get/g7ba40a9296b4e9f7dfcbd16a3fdf59fa4d4f5b645f4802e0c33e136ba9d97b81409ec2ac6fe2e1fb1f99669ea6ff605ce9ad805d2b841d2cf482ae0db99d2231_640.jpg","webformatWidth":457,"webformatHeight":640,"largeImageURL":"https://pixabay.com/get/g4c9417d2d82bef5fa42d2e344c878ca468cb8425d6336dacecb7a6438f22c93f49dce080eaf4f112e960dbd798bd7fb40722ea085eec86a217a3b682a3f7bc62_1280.jpg","imageWidth":3000,"imageHeight":4200,"imageSize":2442403,"views":405996,"downloads":282382,"collections":847,"likes":947,"comments":133,"user_id":199315,"user":"Pfüderi","userImageURL":"https://cdn.pixabay.com/user/2022/03/01/14-54-45-332_250x250.jpg"},{"id":3012515,"pageURL":"https://pixabay.com/photos/lion-roar-africa-animal-wildcat-3012515/","type":"photo","tags":"lion, roar, africa","previewURL":"https://cdn.pixabay.com/photo/2017/12/11/15/34/lion-3012515_150.jpg","previewWidth":150,"previewHeight":95,"webformatURL":"https://pixabay.com/get/g0f10af22f411426638dcf2348e4d70665a1ecf181b5fe5010feba27173f52de8baad3317b7a1a894fb67d5037fa54d983239dd1573a3b44560bf4e301ae3ca45_640.jpg","webformatWidth":640,"webformatHeight":407,"largeImageURL":"https://pixabay.com/get/gfd430e36269c3c93d6eeaf832682754bb2a70bc61b0230593183d2b2c53ff1b59170b38ae358f3ba20efbcacf9317008dc24442397bfff243f6388b53799b296_1280.jpg","imageWidth":3306,"imageHeight":2103,"imageSize":1869137,"views":958908,"downloads":620317,"collections":1634,"likes":2198,"comments":431,"user_id":1546275,"user":"SarahRichterArt","userImageURL":"https://cdn.pixabay.com/user/2016/04/25/20-19-38-614_250x250.jpg"}]
class PixelPay {
PixelPay({
num? total,
num? totalHits,
List<Hits>? hits,}){
_total = total;
_totalHits = totalHits;
_hits = hits;
}
PixelPay.fromJson(dynamic json) {
_total = json['total'];
_totalHits = json['totalHits'];
if (json['hits'] != null) {
_hits = [];
json['hits'].forEach((v) {
_hits?.add(Hits.fromJson(v));
});
}
}
num? _total;
num? _totalHits;
List<Hits>? _hits;
PixelPay copyWith({ num? total,
num? totalHits,
List<Hits>? hits,
}) => PixelPay( total: total ?? _total,
totalHits: totalHits ?? _totalHits,
hits: hits ?? _hits,
);
num? get total => _total;
num? get totalHits => _totalHits;
List<Hits>? get hits => _hits;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['total'] = _total;
map['totalHits'] = _totalHits;
if (_hits != null) {
map['hits'] = _hits?.map((v) => v.toJson()).toList();
}
return map;
}
}
/// id : 736877
/// pageURL : "https://pixabay.com/photos/tree-cat-silhouette-moon-full-moon-736877/"
/// type : "photo"
/// tags : "tree, cat, silhouette"
/// previewURL : "https://cdn.pixabay.com/photo/2015/04/23/21/59/tree-736877_150.jpg"
/// previewWidth : 150
/// previewHeight : 100
/// webformatURL : "https://pixabay.com/get/g23c3d97a250a9c49efe3f9674a48fba61eebb42437052a35a60e544222813c6d651756a4de177551ad6817a808ba2d71_640.jpg"
/// webformatWidth : 640
/// webformatHeight : 427
/// largeImageURL : "https://pixabay.com/get/g972529be72e7aeef825712744208e233f6ae4c5454e9dfa3522218a96b4b0b4c57c04a6d73edb6bdc184ca8f3df8ac1d2e88fce954e5ee336019793819e61fbb_1280.jpg"
/// imageWidth : 1920
/// imageHeight : 1282
/// imageSize : 97150
/// views : 1244651
/// downloads : 631783
/// collections : 2355
/// likes : 2844
/// comments : 573
/// user_id : 909086
/// user : "Bessi"
/// userImageURL : "https://cdn.pixabay.com/user/2019/04/11/22-45-05-994_250x250.jpg"
class Hits {
Hits({
num? id,
String? pageURL,
String? type,
String? tags,
String? previewURL,
num? previewWidth,
num? previewHeight,
String? webformatURL,
num? webformatWidth,
num? webformatHeight,
String? largeImageURL,
num? imageWidth,
num? imageHeight,
num? imageSize,
num? views,
num? downloads,
num? collections,
num? likes,
num? comments,
num? userId,
String? user,
String? userImageURL,}){
_id = id;
_pageURL = pageURL;
_type = type;
_tags = tags;
_previewURL = previewURL;
_previewWidth = previewWidth;
_previewHeight = previewHeight;
_webformatURL = webformatURL;
_webformatWidth = webformatWidth;
_webformatHeight = webformatHeight;
_largeImageURL = largeImageURL;
_imageWidth = imageWidth;
_imageHeight = imageHeight;
_imageSize = imageSize;
_views = views;
_downloads = downloads;
_collections = collections;
_likes = likes;
_comments = comments;
_userId = userId;
_user = user;
_userImageURL = userImageURL;
}
Hits.fromJson(dynamic json) {
_id = json['id'];
_pageURL = json['pageURL'];
_type = json['type'];
_tags = json['tags'];
_previewURL = json['previewURL'];
_previewWidth = json['previewWidth'];
_previewHeight = json['previewHeight'];
_webformatURL = json['webformatURL'];
_webformatWidth = json['webformatWidth'];
_webformatHeight = json['webformatHeight'];
_largeImageURL = json['largeImageURL'];
_imageWidth = json['imageWidth'];
_imageHeight = json['imageHeight'];
_imageSize = json['imageSize'];
_views = json['views'];
_downloads = json['downloads'];
_collections = json['collections'];
_likes = json['likes'];
_comments = json['comments'];
_userId = json['user_id'];
_user = json['user'];
_userImageURL = json['userImageURL'];
}
num? _id;
String? _pageURL;
String? _type;
String? _tags;
String? _previewURL;
num? _previewWidth;
num? _previewHeight;
String? _webformatURL;
num? _webformatWidth;
num? _webformatHeight;
String? _largeImageURL;
num? _imageWidth;
num? _imageHeight;
num? _imageSize;
num? _views;
num? _downloads;
num? _collections;
num? _likes;
num? _comments;
num? _userId;
String? _user;
String? _userImageURL;
Hits copyWith({ num? id,
String? pageURL,
String? type,
String? tags,
String? previewURL,
num? previewWidth,
num? previewHeight,
String? webformatURL,
num? webformatWidth,
num? webformatHeight,
String? largeImageURL,
num? imageWidth,
num? imageHeight,
num? imageSize,
num? views,
num? downloads,
num? collections,
num? likes,
num? comments,
num? userId,
String? user,
String? userImageURL,
}) => Hits( id: id ?? _id,
pageURL: pageURL ?? _pageURL,
type: type ?? _type,
tags: tags ?? _tags,
previewURL: previewURL ?? _previewURL,
previewWidth: previewWidth ?? _previewWidth,
previewHeight: previewHeight ?? _previewHeight,
webformatURL: webformatURL ?? _webformatURL,
webformatWidth: webformatWidth ?? _webformatWidth,
webformatHeight: webformatHeight ?? _webformatHeight,
largeImageURL: largeImageURL ?? _largeImageURL,
imageWidth: imageWidth ?? _imageWidth,
imageHeight: imageHeight ?? _imageHeight,
imageSize: imageSize ?? _imageSize,
views: views ?? _views,
downloads: downloads ?? _downloads,
collections: collections ?? _collections,
likes: likes ?? _likes,
comments: comments ?? _comments,
userId: userId ?? _userId,
user: user ?? _user,
userImageURL: userImageURL ?? _userImageURL,
);
num? get id => _id;
String? get pageURL => _pageURL;
String? get type => _type;
String? get tags => _tags;
String? get previewURL => _previewURL;
num? get previewWidth => _previewWidth;
num? get previewHeight => _previewHeight;
String? get webformatURL => _webformatURL;
num? get webformatWidth => _webformatWidth;
num? get webformatHeight => _webformatHeight;
String? get largeImageURL => _largeImageURL;
num? get imageWidth => _imageWidth;
num? get imageHeight => _imageHeight;
num? get imageSize => _imageSize;
num? get views => _views;
num? get downloads => _downloads;
num? get collections => _collections;
num? get likes => _likes;
num? get comments => _comments;
num? get userId => _userId;
String? get user => _user;
String? get userImageURL => _userImageURL;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['id'] = _id;
map['pageURL'] = _pageURL;
map['type'] = _type;
map['tags'] = _tags;
map['previewURL'] = _previewURL;
map['previewWidth'] = _previewWidth;
map['previewHeight'] = _previewHeight;
map['webformatURL'] = _webformatURL;
map['webformatWidth'] = _webformatWidth;
map['webformatHeight'] = _webformatHeight;
map['largeImageURL'] = _largeImageURL;
map['imageWidth'] = _imageWidth;
map['imageHeight'] = _imageHeight;
map['imageSize'] = _imageSize;
map['views'] = _views;
map['downloads'] = _downloads;
map['collections'] = _collections;
map['likes'] = _likes;
map['comments'] = _comments;
map['user_id'] = _userId;
map['user'] = _user;
map['userImageURL'] = _userImageURL;
return map;
}
}
Comments
Post a Comment