kv 1.0.8 copy "kv: ^1.0.8" to clipboard
kv: ^1.0.8 copied to clipboard

Another Key-Value storage for Dart.

example/main.dart

import 'package:kv/kv.dart';

void main() {
  var memoryKV = KV();
  memoryKV.listen("key", (newVal) {
    print('You will set: $newVal');
  });
  memoryKV.set("key", "new value");
  print('Welcome by Memory: ${memoryKV.get("key")}');

  var fileKV = KV(FileStorage("example/file_storage.json"));
  var fileKVCopy = KV(FileStorage("example/file_storage_copy.json"));
  fileKV.listen("key", (newVal) {
    print('You will set: $newVal');
  });
  var value = fileKV.get("key");
  if (value == null) {
    fileKV.set("key", "new file");
  }
  fileKVCopy.set("key", "new file copy");
  var valueCopy = fileKVCopy.get("key");
  print('Copy value: $valueCopy');
  print('Welcome by File: ${fileKV.get("key")}');

  var userDto = UserDTO("John", "John@gmail.com", "123456");

  fileKV.set("newKey", userDto);
  var keys = fileKV.keys();
  print('Keys: $keys');
  print(
      'Last key: ${keys.last}, and value is ${fileKV.get(keys.last) as UserDTO}');
}

class UserDTO {
  final String name;
  final String email;
  final String password;

  UserDTO(this.name, this.email, this.password);

  UserDTO.fromJson(Map<String, dynamic> json)
      : name = json['name'],
        email = json['email'],
        password = json['password'];

  Map<String, dynamic> toJson() => {
        'name': name,
        'email': email,
        'password': password,
      };
}
2
likes
140
points
62
downloads

Publisher

verified publisherspeedphp.com

Weekly Downloads

Another Key-Value storage for Dart.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on kv