Developer
Vault Storage
Universal solution for secure store data on device.
- NoSQL Hive
- Secure Storage
- Local Files
Installation
dart pub global activate eit_vault --hosted-url=https://gitea.whitelabel.mobile.embedit.dev/api/packages/platform/pub/
!IMPORTANT You need access token for fetching from private pub repository. ELI add token automatically
Usage
You should init EitStorage during app initialization and use all the necessary boxes
final vault = await EitVault.init();
final authVault = vault.createPersistantVault('auth', fromJson: Auth.fromJson);
/// create a cache
final authCache = vault.createPersistantCache('authCache', fromJson: Auth.fromJson);
///
final taskVault = vault.createPersistantVault('tasks', fromJson: Task.fromJson);
you can open box manualy
await locator<SettingsBox>().openBox();
Config
You can optionally include EitStorageConfig
in the init
method.
await EitStorage.init(
config: EitStorageConfig(
/// Representing the path where data will be stored.
/// This path can only be one level deep (it cannot contain a path separator).
/// The value is ignored in web environments.
subDir: 'storage',
),
boxes: [...],
);
If you update the subDir
from empty to a specific path in an existing app, the package will attempt to migrate the data to the specified subDir
.
Box
This a place where you can save and retrieve data from.
class TokenBox extends EitBox {
TokenBox() : super(boxKey: boxName);
static const String boxName = 'token_box';
// save values
Future<void> save(String accessToken, String refreshToken) {
return Future.wait([
box.put(keyAccessToken, accessToken),
box.put(keyRefreshToken, refreshToken),
]);
}
/// get values
(String, String) getTokens(){
return (box.get(keyAccessToken), box.get(keyRefreshToken));
}
...
}
Secure encryption
if you want to use encryptedbox then you have to use isEncrypted
attribute.
you can define your custom encryptionKeyName
for the specific box if you want to use different key for this box.
class TokenBox extends EitBox {
TokenBox() : super(
boxKey: boxName,
isEncrypted: true,
/// you can define your custom encryption key instead of generic one.
encryptionKeyName: 'MyCustomEncryptionKey'
);
static const String boxName = 'token_box';
...
}
Lazy loading
open box when you need it.
class TokenBox extends EitBox {
TokenBox() : super(
boxKey: boxName,
isLazy: true,
isEncrypted: true,
);
static const String boxName = 'token_box';
...
}