import 'dart:io'; import 'dart:typed_data'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:spotiflac_android/services/user_profile_store.dart'; final userProfileStoreProvider = Provider( (ref) => UserProfileStore(), ); final userProfileProvider = AsyncNotifierProvider( UserProfileNotifier.new, ); class UserProfileNotifier extends AsyncNotifier { @override Future build() => ref.watch(userProfileStoreProvider).read(); Future restoreFromBackup(UserProfile profile) async { final path = profile.photoPath; final photo = path == null ? null : await prepareProfilePhoto(await File(path).readAsBytes()); await save(name: profile.name, photo: photo, removePhoto: photo == null); } Future save({ required String name, Uint8List? photo, bool removePhoto = false, }) async { await future; final profile = await ref .read(userProfileStoreProvider) .save(name: name, photo: photo, removePhoto: removePhoto); state = AsyncData(profile); } }