An unofficial, platform independent, client for the Unsplash API. Unsplash provides royalty-free images.
The client is platform independent, since it uses http to make requests.
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
final client = UnsplashClient( settings: ClientSettings(credentials: AppCredentials( accessKey: '...', secretKey: '...', )), );
:warning: When you are done using a client instance, make sure to call it's
Get a random photo
// Call `goAndGet` to execute the [Request] returned from `random` // and throw an exception if the [Response] is not ok. final photos = await client.photos.random(count: 1).goAndGet(); // The api returns a `Photo` which contains metadata about the photo and urls to download it. final photo = photos.first;
Photo comes with a set of urls for variants of the photo of different sizes, such as
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
photo.urls.raw to generate an
Uri for a custom variant:
final custom = photo.urls.raw.resizePhoto(width: 400, height: 400);
See examples tab for a runnable example.