HopeClient class

The central registry for all active queries.

Initialize once in main before runApp:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await HopeClient.init(
    maxSize: 1024 * 1024,
    defaultTTL: Duration(minutes: 5),
    evictionPolicy: EvictionPolicy.lru,
  );

  runApp(MyApp());
}

Properties

cache CacheManager
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getOrCreate<T>({required List queryKey, required Future<T> fetcher(dynamic pageParam), required HopeOptions options, dynamic getNextPageParam(T lastResult)?}) HopeController<T>
Returns existing controller or creates a new one for this key. Increments the reference count every time a widget subscribes.
invalidate(List queryKey) Future<void>
Invalidate a query by key — triggers a fresh fetch in all listening widgets.
invalidateAll() Future<void>
Invalidate all active queries at once.
invalidatePrefix(List prefix) Future<void>
Invalidate all queries whose key starts with the given prefix.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
prefetch<T>({required List queryKey, required Future<T> fetcher()}) Future<void>
Prefetch a query before the user navigates to a screen. Writes directly to cache — no controller created, no reference count touched.
release(List queryKey) → void
Called by HopeBuilder on dispose. Decrements the reference count — disposes the controller only when no widgets are listening to this key anymore.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

instance HopeClient
The global HopeClient instance. Must call init first.
no setter

Static Methods

init({required int maxSize, required Duration defaultTTL, required EvictionPolicy evictionPolicy, CacheStore? storage}) Future<void>
Initialize HopeClient. Call once in main before runApp. Subsequent calls are no-ops — safe to call multiple times.