import 'dart:io'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'agent_credentials.g.dart'; abstract interface class AgentCredentialStore { Future read(String id); Future write(String id, String value); Future delete(String id); } @Riverpod(keepAlive: true) AgentCredentialStore agentCredentialStore(Ref ref) { final storage = Platform.isMacOS ? const FlutterSecureStorage( mOptions: MacOsOptions(usesDataProtectionKeychain: false), ) : const FlutterSecureStorage(); return FlutterSecureAgentCredentialStore(storage); } class FlutterSecureAgentCredentialStore implements AgentCredentialStore { FlutterSecureAgentCredentialStore(this._storage); final FlutterSecureStorage _storage; @override Future read(String id) => _storage.read(key: id); @override Future write(String id, String value) => _storage.write(key: id, value: value); @override Future delete(String id) => _storage.delete(key: id); } class MemoryAgentCredentialStore implements AgentCredentialStore { final Map _values = {}; @override Future read(String id) async => _values[id]; @override Future write(String id, String value) async => _values[id] = value; @override Future delete(String id) async => _values.remove(id); }