Skip to content

Abstraction for persisting and reading data to platform specific storage.

License

Notifications You must be signed in to change notification settings

salihagic/storage_repository

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Storage repository

Abstraction for persisting and reading data to platform specific storage. You can also find this package on pub as storage_repository

Usage

Future main() async {
    WidgetsFlutterBinding.ensureInitialized();
    //This must be called once per application lifetime
    await StorageRepository.initFlutter();

    //Instantiate a basic storage repository
    IStorageRepository storageRepository = StorageRepository();
    //or use a secure version of storage repository
    //final storageRepository = SecureStorageRepositoryImpl();
    //init must be called, preferably right after the instantiation
    await storageRepository.init();

    await storageRepository.set('some_string_key', 'Some string');
    await storageRepository.set('some_int_key', 0);
    //dynamic keys are also possible
    await storageRepository.set(1, 1);

    //result: Some string (dynamic)
    print(await storageRepository.get('some_string_key'));

    //result: 0 (dynamic)
    print(await storageRepository.get('some_int_key'));

    //result: 1 (dynamic)
    print(await storageRepository.get(1));

    //result: 1 (int?)
    print(await storageRepository.get(1));

    await storageRepository.delete('some_string_key');

    await storageRepository.log();

    await storageRepository.clear();
}

About

Abstraction for persisting and reading data to platform specific storage.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published