Developer

Storage

Secure key-pair storage with easy implementation and configuration with platform.


Installation

dart pub global activate eit_storage  --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


  await EitStorage.init(
    boxes: [
      locator<SettingsBox>(),
      locator<TokenBox>(),
    ],
  );
  // await box.put(key, value);

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';
  
  ...
}

Copyright © 2025. All rights reserved.