bot_storage 1.1.1 copy "bot_storage: ^1.1.1" to clipboard
bot_storage: ^1.1.1 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();
}
 
22
likes
160
points
382
downloads

Publisher

verified publisherflutterbots.dev

Weekly Downloads

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

meta, rxdart

More

Packages that depend on bot_storage