cached_storage 2.0.1 copy "cached_storage: ^2.0.1" to clipboard
cached_storage: ^2.0.1 copied to clipboard

A storage addon for cached_query. Built on top of the Sqflite package.

example/main.dart

import 'package:cached_query_flutter/cached_query_flutter.dart';
import 'package:cached_storage/cached_storage.dart';

// Full project example here: https://github.com/D-James-GH/cached_query/tree/main/examples/query_builder
void main() async {
  CachedQuery.instance.configFlutter(
    storage: await CachedStorage.ensureInitialized(),
    config: const QueryConfig(),
  );
  final joke = await getJoke().result;
}

Query<JokeModel?> getJoke() {
  return Query<JokeModel>(
    key: 'joke',
    config: QueryConfig(
      storageDeserializer: (dynamic json) =>
          JokeModel.fromJson(json as Map<String, dynamic>),
    ),
    queryFn: () async {
      final req = client.get(
        Uri.parse("https://icanhazdadjoke.com/"),
        headers: {"Accept": "application/json"},
      );
      final res = await req;
      return Future.delayed(
        const Duration(milliseconds: 400),
        () => JokeModel.fromJson(
          jsonDecode(res.body) as Map<String, dynamic>,
        ),
      );
    },
  );
}
8
likes
140
pub points
78%
popularity

Publisher

verified publishercachedquery.dev

A storage addon for cached_query. Built on top of the Sqflite package.

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (LICENSE)

Dependencies

cached_query, flutter, path, sqflite

More

Packages that depend on cached_storage