mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-30 13:19:44 +02:00
feat(profile): add local profiles with backup and restore
Move Mornye Settings to the Home avatar and keep search above the profile card. Center the metadata artwork and actions, and make artist names clickable in the Material player.
This commit is contained in:
1 parent
5b519070a3
commit
d8d46108bc
19 files changed
+1003
-80
No files matched your search
@@ -0,0 +1,39 @@
|
||||
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<UserProfileStore>(
|
||||
(ref) => UserProfileStore(),
|
||||
);
|
||||
|
||||
final userProfileProvider =
|
||||
AsyncNotifierProvider<UserProfileNotifier, UserProfile>(
|
||||
UserProfileNotifier.new,
|
||||
);
|
||||
|
||||
class UserProfileNotifier extends AsyncNotifier<UserProfile> {
|
||||
@override
|
||||
Future<UserProfile> build() => ref.watch(userProfileStoreProvider).read();
|
||||
|
||||
Future<void> 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<void> 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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user