bot_storage 1.0.5 icon indicating copy to clipboard operation
bot_storage: ^1.0.5 copied to clipboard

A useful package provide an interface to handle read, write and delete operations in reactive way

🤖 Bot Storage #

pub package style: very good analysis License: MIT

A useful package provide an interface to handle read, write and delete operations in reactive way.

Usage #

Add a dependency in your pubspec.yaml:

dependencies:
  bot_storage: ^1.0.1

Simple usage using BotMemoryStorage:

import 'package:bot_storage/bot_storage.dart';

void main() {
  final botStorage = BotStorageImpl();
  botStorage.stream.listen(print);
  await botStorage.write('new value');
  await botStorage.delete();
  botStorage.close();
}

class BotStorageImpl extends BotMemoryStorage<String> {
  @override
  String? get initValue => 'init value';
}

Or implement BotStorage with SharedPreference (or any other local storage) like this:

class BotStorageImpl extends BotStorage<String> with BotStorageMixin<String> {
  BotStorageImpl(this._storage);
  
  final SharedPreference _storage;

  @override
  FutureOr<void> delete() async {
    super.delete();
    return _storage.remove();
  }

  @override
  String? read() {
    return _storage.getString();
  }

  @override
  FutureOr<void> write(String? value) async {
    super.write(value);
    _storage.setString(value);
  }
}

void main() async {
  final botStorage = BotStorageImpl();
  botStorage.stream.listen(print);
  await botStorage.write('event');
  await botStorage.delete();
  botStorage.close();

}

You can use BotStorageWrapper concrete class

void main(){
  final BotStorageWrapper botStorageWrapper = BotStorageWrapper<String>(
    delete: () {
      // delete from your storage
    },
    read: () {
      // read from your storage
      return 'none';
    },
    write: (value) {
      // write to your storage
    },
  );
  botStorageWrapper.stream.listen(print);
  botStorageWrapper.write('new value');
  botStorageWrapper.delete();
  botStorageWrapper.close();
}
 
18
likes
140
pub points
27%
popularity

Publisher

verified publisher iconflutterbots.dev

A useful package provide an interface to handle read, write and delete operations in reactive way

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

meta, rxdart

More

Packages that depend on bot_storage