writeProfileInfo method
Future<void>
writeProfileInfo(
{ - bool overwrite = false,
- bool throwOnError = false,
})
override
Implementation
@override
Future<void> writeProfileInfo({bool overwrite = false, bool throwOnError = false}) async {
neomLogger.d('writeProfileInfo');
try {
final service = userServiceImpl;
final user = service.user;
final profile = service.profile;
final sourceUserId = user.id;
final sourceProfileId = profile.id;
// Read scalar values once. The account/profile models are mutable and a
// different session may be published while opening the local box.
final snapshot = Map<String, dynamic>.unmodifiable({
AppHiveConstants.userId: sourceUserId,
AppHiveConstants.username: user.name,
AppHiveConstants.profileId: sourceProfileId,
AppHiveConstants.photoUrl: user.photoUrl,
AppHiveConstants.firstTime: false,
});
final box = await getBox(AppHiveBox.profile.name);
final currentService = userServiceImpl;
if (!identical(currentService, service) ||
!identical(currentService.user, user) ||
!identical(currentService.profile, profile) ||
currentService.user.id != sourceUserId ||
currentService.profile.id != sourceProfileId) {
return;
}
String userId = box.get(AppHiveConstants.userId, defaultValue: '');
if(userId.isEmpty || overwrite) {
// No awaits between the identity check and submitting this single
// snapshot. Do not mix fields from a session that changes mid-write.
await box.putAll(snapshot);
}
} catch (e, st) {
NeomErrorLogger.recordError(e, st, module: 'neom_core', operation: 'writeProfileInfo');
if (throwOnError) rethrow;
}
}