修复白屏BUG、UI 边界溢出 BUG
This commit is contained in:
@@ -17,11 +17,34 @@ class ProfileNotifier extends AsyncNotifier<UserProfile> {
|
||||
Future<UserProfile> build() async {
|
||||
final isar = await ref.watch(isarProvider.future);
|
||||
final profile = await isar.userProfiles.get(AppDefaults.singletonId);
|
||||
if (profile != null) return profile;
|
||||
// Bootstrap should have created one; create defensively.
|
||||
final fresh = UserProfile.createDefault();
|
||||
await isar.writeTxn(() => isar.userProfiles.put(fresh));
|
||||
return fresh;
|
||||
if (profile == null) {
|
||||
// Bootstrap should have created one; create defensively.
|
||||
final fresh = UserProfile.createDefault();
|
||||
await isar.writeTxn(() => isar.userProfiles.put(fresh));
|
||||
return fresh;
|
||||
}
|
||||
if (_isLocalAvatarMissing(profile)) {
|
||||
return _clearMissingLocalAvatar(profile);
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
|
||||
bool _isLocalAvatarMissing(UserProfile profile) {
|
||||
if (profile.avatarSource != AvatarSource.localFile) return false;
|
||||
final path = profile.avatarLocalPath?.trim();
|
||||
if (path == null || path.isEmpty) return true;
|
||||
return !File(path).existsSync();
|
||||
}
|
||||
|
||||
Future<UserProfile> _clearMissingLocalAvatar(UserProfile current) async {
|
||||
final updated = current.copyWith(
|
||||
avatarAssetPath: AppDefaults.defaultAvatarAssetPath,
|
||||
avatarLocalPath: null,
|
||||
avatarSource: AvatarSource.asset,
|
||||
);
|
||||
final isar = await ref.read(isarProvider.future);
|
||||
await isar.writeTxn(() => isar.userProfiles.put(updated));
|
||||
return updated;
|
||||
}
|
||||
|
||||
Future<void> updateNickname(String nickname) async {
|
||||
@@ -68,6 +91,19 @@ class ProfileNotifier extends AsyncNotifier<UserProfile> {
|
||||
Future<void> resetAvatar() async {
|
||||
final current = state.value;
|
||||
if (current == null) return;
|
||||
|
||||
final path = current.avatarLocalPath;
|
||||
if (path != null && path.isNotEmpty) {
|
||||
final file = File(path);
|
||||
if (await file.exists()) {
|
||||
try {
|
||||
await file.delete();
|
||||
} catch (_) {
|
||||
// Best-effort cleanup; profile reset still proceeds.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final updated = current.copyWith(
|
||||
avatarAssetPath: AppDefaults.defaultAvatarAssetPath,
|
||||
avatarLocalPath: null,
|
||||
|
||||
Reference in New Issue
Block a user