intermediate

This commit is contained in:
Fabian Freund
2025-01-23 14:03:55 +01:00
parent bd45ed64ee
commit 78c17a70c5
122 changed files with 8730 additions and 1662 deletions
@@ -0,0 +1,49 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:lensai/features/user/data/providers.dart';
import 'package:pocketbase/pocketbase.dart';
import 'package:riverpod/riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'providers.g.dart';
const _authKey = 'pb_auth';
@Riverpod()
Stream<double> iconCacheSizeMegabytes(Ref ref) {
final repository = ref.watch(userDatabaseProvider);
return repository.cacheDao.iconCacheSize().watchSingle();
}
@Riverpod()
Future<String?> _storedAuthData(Ref ref) {
const secureStorage = FlutterSecureStorage();
return secureStorage.read(key: _authKey);
}
@Riverpod(keepAlive: true)
AsyncAuthStore authStore(Ref ref) {
const secureStorage = FlutterSecureStorage();
final intial =
ref.watch(_storedAuthDataProvider.select((value) => value.valueOrNull));
return AsyncAuthStore(
initial: intial,
save: (data) async {
await secureStorage.write(key: _authKey, value: data);
},
);
}
@Riverpod()
Stream<AuthStoreEvent> authState(Ref ref) {
final authStore = ref.watch(authStoreProvider);
return authStore.onChange;
}
@Riverpod(keepAlive: true)
PocketBase pocketBase(Ref ref) {
final authStore = ref.watch(authStoreProvider);
return PocketBase('http://192.168.2.104:8090', authStore: authStore);
}