import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'auth_provider.dart' show localDbProvider; const aiConsentVersion = 'ai-data-consent-v1'; class AiConsentState { final bool isLoading; final bool granted; final String? userId; const AiConsentState({ this.isLoading = true, this.granted = false, this.userId, }); AiConsentState copyWith({bool? isLoading, bool? granted, String? userId}) { return AiConsentState( isLoading: isLoading ?? this.isLoading, granted: granted ?? this.granted, userId: userId ?? this.userId, ); } } final aiConsentProvider = NotifierProvider( AiConsentNotifier.new, ); class AiConsentNotifier extends Notifier { @override AiConsentState build() => const AiConsentState(); String _key(String userId) => '$aiConsentVersion:$userId'; Future load(String userId) async { state = AiConsentState(isLoading: true, userId: userId); final value = await ref.read(localDbProvider).read(_key(userId)); state = AiConsentState( isLoading: false, granted: value == 'granted', userId: userId, ); } Future grant(String userId) async { await ref.read(localDbProvider).write(_key(userId), 'granted'); state = AiConsentState(isLoading: false, granted: true, userId: userId); } Future revoke(String userId) async { await ref.read(localDbProvider).delete(_key(userId)); state = AiConsentState(isLoading: false, granted: false, userId: userId); } }