Skip to content
pubscout

sanity_client

2.0.0, released 9 days ago by vyuh.tech

Dart client for Sanity.io with GROQ queries and live updates

WASM-ready
$ flutter pub add sanity_client
Source repository

What it does

Provides a type‑safe way to execute GROQ queries against Sanity.io’s HTTP API. It also supports live data streams, CDN usage, and image URL building.

AI-written summary of version 2.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • Fetching structured content from Sanity.io
  • Implementing live content updates
  • Building image URLs with transformations

Skip it when

  • Using older Dart/Flutter versions (requires Dart 3.14+ and Flutter 3.50+)
  • Projects that already use a different Sanity client

Strengths

  • Strong type safety for queries and responses
  • Built‑in live streaming with automatic reconnects
  • Flexible image URL builder and external service support

Weaknesses

  • Requires recent Dart/Flutter versions
  • Breaking changes in v2.0.0 may need migration

Setup

Kind
Flutter widgets
Effort
Medium
Code generation
Yes (build_runner)
Direct dependencies
2

Add sanity_client to pubspec.yaml. No build_runner or codegen required.

final client = SanityClient(
  SanityConfig(
    projectId: 'your_project_id',
    dataset: 'your_dataset',
    apiVersion: 'v2024-02-16',
    useCdn: true,
  ),
);

final movies = await client.fetch('''
  *[_type == "movie"]{_id, title, releaseDate}
''');

Alternatives

Packages that do the same job and could replace sanity_client.

Works with

Packages commonly used together with sanity_client: ones it builds on, ones built on it, and its own family.