This is a client for the access to the local storage service.
It's base on Isar package.
Add the following to your pubspec.yaml
file:
dependencies:
secure_storage_client: ^0.0.1
git:
url: https://github.com/arcas0803/local_storage_client.git
ref: main
import 'package:local_storage_client/local_storage_client.dart';
final localStorage = LocalStorage<String, String>();
localStorage.read(id: 'your_id');
final localStorage = LocalStorage<String, String>();
localStorage.write(value: 'your_value');
final localStorage = LocalStorage<String, String>();
localStorage.delete(id: 'your_id');
final localStorage = LocalStorage<String, String>();
secureStorage.deleteAll();
final localStorage = LocalStorage<String, String>();
localStorage.readAll();
It's possible to enable the logger to see the logs of the client.
Just pass the logger
parameter to the constructor.
final logger = Logger();
final localStorage = LocalStorage(logger: logger);
It's possible to handle telemetry events passing to methods to the constructor.
final localStorage = LocalStorage(
FutureOr<void> Function(Failure)? telemetryOnError,
FutureOr<void> Function()? telemetryOnSuccess,
);
Telemetry on error is called when an error occurs.
Telemetry on success is called when the method is executed successfully.
The exceptions available are:
-
LocalStorageReadFailure
when the read method fails. -
LocalStorageWriteFailure
when the write method fails. -
LocalStorageKeyNotFoundFailure
when the key is not found. -
LocalStorageValueNotFoundFailure
when the value is not found. -
LocalStorageIntializationFailure
when the initialization fails.
There is an class called LocalStorageFailureUtil
with a method called getFailureNameUI
to get a user friendly message from the exception.
final failureName = LocalStorageFailureUtil.getFailureNameUI(
context: context,
failure:failure);