搜索插件、代码仓与 APP 分类

插件详情v4.0.0

unsplash_client

Unsplash 提供免费的高分辨率照片。这是一个用于其 REST API 的客户端。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
3790
喜欢数
67
Pub 分数
160

安装插件

flutter pub add unsplash_client

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

unsplash_client 包是 Unsplash REST API 的 Dart 客户端,使开发者能够在 Flutter 应用中直接获取高分辨率、可免费使用的照片。该包通过提供对搜索、获取和管理照片、用户及收藏夹等端点的结构化访问,简化了与 Unsplash 图像库的集成。该包支持所有主要平台,包括移动设备、网页和桌面端,非常适合需要动态且视觉丰富的应用。凭借简洁直观的 API,它减少了处理 Unsplash 数据时的样板代码。

适合场景

  • 获取随机或搜索的图片
  • 显示精选照片合集
  • 将免费股票照片集成到应用程序中
  • 构建视觉内容发现功能
  • 通过高质量图像增强应用UI

主要特点

  • 简单的 REST API 包装器
  • 支持所有平台(Android、iOS、Web、macOS、Windows、Linux)
  • 照片、用户和收藏夹的内置模型
  • 轻松搜索和分页
  • 类型安全的响应
  • 活跃维护和开源

适合对象

  • 需要免费股票图片的应用
  • 注重设计或视觉内容的平台
  • 照片画廊或灵感应用
  • 使用 Flutter 的跨平台项目
  • 寻求可靠图像来源的开发者

使用建议

  • 需要来自 Unsplash 的 API 密钥
  • 每个 API 密钥都有速率限制
  • 仅限 Unsplash 的图像库
  • 依赖网络连接
  • 可能需要缓存以供离线使用

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

pub.dev package page GitHub Actions CI GitHub Stars

Unsplash provides free high-resolution photos. This is a client for their REST API.


If you're looking for a database solution, check out cbl, another project of mine. It brings Couchbase Lite to standalone Dart and Flutter, with support for:

  • Full-Text Search,
  • Expressive Queries,
  • Data Sync,
  • Change Notifications

and more.


Limitations

Endpoints that act on behalf of a user are not implemented, yet.If that is something you need, please comment on this issue.

Requirements

You need to register as a developer and create an Unsplash app to access the API.

Getting started

Create an UnsplashClient

Use the credentials for your app, obtained from the developer portal, to create an UnsplashClient:

final client = UnsplashClient(
  settings: ClientSettings(credentials: AppCredentials(
    accessKey: '...',
    secretKey: '...',
  )),
);

:warning: When you are done using a client instance, make sure to call it's close method.

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 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

The example is a simple CLI app that fetches a few random photos.


Gabriel Terwesten • GitHub @blaugold • Twitter @GTerwesten • Medium @gabriel.terwesten

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目