Skip to content
pubscout

fresh

0.7.0, released 9 days ago by felangel.dev

Core token refresh library for managing authentication token lifecycles.

WASM-ready
$ flutter pub add fresh
Source repository

What it does

Exposes core components common to various token refresh implementations such as REST or GraphQL. Provides token lifecycle management, single-flight refresh coordination, and stream-based authentication state tracking.

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

Use it when

  • You are building a custom HTTP client integration that requires token refresh logic.
  • You need to coordinate concurrent refresh attempts to share a single in-flight operation.

Skip it when

  • You are using standard clients like Dio or the http package (use fresh_dio or fresh_http integration packages instead).
  • You do not need token refresh functionality.

Strengths

  • Single-flight refresh coordination prevents duplicate concurrent refresh requests.
  • Stream-based authentication status tracking.
  • Extensible token base class and custom storage support.

Weaknesses

  • Most users must rely on separate integration packages for standard clients.
  • Requires writing custom boilerplate if building a non-standard integration.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1

Not documented

class MyHttpFresh extends MyHttpClient with FreshMixin<OAuth2Token> {
  MyHttpFresh({required TokenStorage<OAuth2Token> tokenStorage}) {
    this.tokenStorage = tokenStorage;
  }

  @override
  Future<OAuth2Token> performTokenRefresh(OAuth2Token? token) async {
    final response = await post('/auth/refresh', body: {'refresh_token': token?.refreshToken});
    return OAuth2Token(
      accessToken: response['access_token'],
      refreshToken: response['refresh_token'],
    );
  }
}

Alternatives

Packages that do the same job and could replace fresh.

Works with

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