This is a simple flutter project which will search the photos from Unsplash website and get the image details. To search images from Unsplash we need to create an application in unsplash dashboard and get API key to search images.
Read How to create unsplash application on official website. Once you create an application you will see your app list on unsplash dashboard like below
Now create flutter application in Android studio or any other Flutter IDE
This project developed with Flutter Bloc pattern
This project used below dependencies
cached_network_image:
equatable:
flutter_bloc:
http:
To search Photos we will use below code
try {
var unsplashApiKey="";
final url =
'$_unsplashBaseUrl/search/photos?client_id=$unsplashApiKey&page=$page&per_page=$numPerPage&query=$query';
final response = await _httpClient.get(Uri.parse(url));
if (response.statusCode == 200) {
final Map<String, dynamic> data = jsonDecode(response.body);
final List results = data['results'];
final List<Photo> photos =
results.map((e) => Photo.fromMap(e)).toList();
return photos;
}
throw Failure();
} catch (_) {
throw Failure();
}
|