bot_storage 1.1.1 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 #
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();
}