unsplash_client 0.3.0 unsplash_client: ^0.3.0 copied to clipboard
An unofficial, platform independent client for accessing the Unsplash.com REST api.
unsplash_client #
An unofficial client for the unsplash api.
The client is platform independent, since it uses http to make requests.
Setup #
-
You need to register as a developer and create an unsplash app to access the API.
-
Obtain the credentials for your app from the developer portal and create an
UnsplashClient
:
final client = UnsplashClient(
settings: ClientSettings(credentials: AppCredentials(
accessKey: '...',
secretKey: '...',
)),
);
⚠️ When you are done using a client instance, make sure to call it's
close
method.
Usage #
Get a random photo #
// Make the request.
final response = await client.photos.random(count: 1).go();
// Check that the request was successful.
if (!response.isOk) {
throw 'Something is wrong: $response';
}
// The api returns a `Photo` which contains metadata about the photo and urls to download it.
final photo = response.data.first;
Photo variants #
A Photo
comes with a set of urls for variants of the photo of different sizes, such as regular
and thumb
:
final thumb = photo.urls.thumb;
If the provided variants are not a good fit for your use, you can generate urls where you specify size, quality, fit and other parameters.
Call the extension method Uri.resizePhoto
on photo.urls.raw
to generate an Uri
for a custom variant:
final custom = photo.urls.raw.resizePhoto(width: 400, height: 400);
Example #
See examples tab for a runnable example.
TODO #
- ❌ Get the user’s profile
- ❌ Update the current user’s profile
- ❌ Update a photo
- ❌ Like a photo
- ❌ Unlike a photo
- ❌ Create a new collection
- ❌ Update an existing collection
- ❌ Delete a collection
- ❌ Add a photo to a collection
- ❌ Remove a photo from a collection