location fixes (#981)

This commit is contained in:
Neeraj Gupta 2023-04-13 09:47:32 +05:30 committed by GitHub
commit bc6cdad1d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 24 deletions

View file

@ -162,7 +162,7 @@ class EntityService {
final EntityKey response = await _gateway.getKey(type);
encryptedKey = response.encryptedKey;
header = response.header;
_prefs.setString(_getEntityKeyPrefix(type), encryptedKey);
await _prefs.setString(_getEntityKeyPrefix(type), encryptedKey);
_prefs.setString(_getEntityHeaderPrefix(type), header);
}
final entityKey = CryptoUtil.decryptSync(
@ -171,18 +171,15 @@ class EntityService {
Sodium.base642bin(header),
);
return entityKey;
} on EntityKeyNotFound catch (e) {
_logger.info(
"EntityKeyNotFound generating key for type $type ${e.stackTrace}");
} on EntityKeyNotFound {
_logger.info("EntityKeyNotFound generating key for type $type");
final key = CryptoUtil.generateKey();
final encryptedKeyData = CryptoUtil.encryptSync(key, _config.getKey()!);
await _gateway.createKey(
type,
Sodium.bin2base64(encryptedKeyData.encryptedData!),
Sodium.bin2base64(encryptedKeyData.nonce!),
);
_prefs.setString(_getEntityKeyPrefix(type), encryptedKey);
_prefs.setString(_getEntityHeaderPrefix(type), header);
encryptedKey = Sodium.bin2base64(encryptedKeyData.encryptedData!);
header = Sodium.bin2base64(encryptedKeyData.nonce!);
await _gateway.createKey(type, encryptedKey, header);
await _prefs.setString(_getEntityKeyPrefix(type), encryptedKey);
await _prefs.setString(_getEntityHeaderPrefix(type), header);
return key;
} catch (e, s) {
_logger.severe("Failed to getOrCreateKey for type $type", e, s);

View file

@ -46,6 +46,7 @@ class LocationService {
//Converting the unit from kilometers to degrees for a and b as that is
//the unit on the caritesian plane
try {
final a =
(radius * _scaleFactor(centerPoint.latitude!)) / kilometersPerDegree;
final b = radius / kilometersPerDegree;
@ -59,6 +60,9 @@ class LocationService {
await EntityService.instance
.addOrUpdate(EntityType.location, json.encode(locationTag.toJson()));
Bus.instance.fire(LocationTagUpdatedEvent(LocTagEventType.add));
} catch (e, s) {
_logger.severe("Failed to add location tag", e, s);
}
}
///The area bounded by the location tag becomes more elliptical with increase

View file

@ -118,6 +118,7 @@ class _AddLocationSheetState extends State<AddLocationSheet> {
popNavAfterSubmission: false,
shouldUnfocusOnClearOrSubmit: true,
alwaysShowSuccessState: true,
textCapitalization: TextCapitalization.words,
textEditingController: _textEditingController,
isEmptyNotifier: _isEmptyNotifier,
),