smart_repository 0.1.0
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();
}