smart_repository 0.1.0 copy "smart_repository: ^0.1.0" to clipboard
smart_repository: ^0.1.0 copied to clipboard

Policy-driven coordination for remote and local repository data.

example/smart_repository_example.dart

import 'package:smart_repository/smart_repository.dart';

Future<void> main() async {
  String? cachedUser = 'Cached Ada';

  final repository = SmartRepository<String>(
    remote: () async => 'Fresh Ada',
    local: () async => cachedUser,
    saveLocal: (user) async => cachedUser = user,
    config: const SmartRepositoryConfig(
      defaultPolicy: RepositoryPolicy.staleWhileRevalidate,
    ),
  );

  final subscription = repository.watch().listen(print);
  final result = await repository.get();

  if (result case RepositorySuccess(:final data)) print(data);

  await subscription.cancel();
  await repository.dispose();
}
0
likes
0
points
476
downloads

Publisher

verified publisherpinz.dev

Weekly Downloads

Policy-driven coordination for remote and local repository data.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on smart_repository