Browse Source

Updated the example code

tags/v2.0.0
Cédric Belin 3 months ago
parent
commit
66cf4fa3c7
1 changed files with 30 additions and 27 deletions
  1. +30
    -27
      example/main.dart

+ 30
- 27
example/main.dart View File

@@ -3,44 +3,47 @@ import "package:webstorage/webstorage.dart";

/// Tests the cookie service.
void main() {
final storage = LocalStorage();
final service = LocalStorage();

// Query the storage.
print(storage.containsKey("foo")); // false
print(storage.containsKey("baz")); // false
print(storage.isEmpty); // true
print(storage.keys); // []
print(service.containsKey("foo")); // false
print(service.containsKey("baz")); // false
print(service.isEmpty); // true
print(service.keys); // []

// Write to the storage.
storage["foo"] = "bar";
print(storage.containsKey("foo")); // true
print(storage.length); // 1
print(storage.keys); // ["foo"]
service["foo"] = "bar";
print(service.containsKey("foo")); // true
print(service.length); // 1
print(service.keys); // ["foo"]

storage.setObject("baz", <String, int>{"qux": 123});
print(storage.containsKey("baz")); // true
print(storage.length); // 2
print(storage.keys); // ["foo", "baz"]
service.setObject("baz", {"qux": 123});
print(service.containsKey("baz")); // true
print(service.length); // 2
print(service.keys); // ["foo", "baz"]

// Read the storage.
print(storage["foo"].runtimeType); // "String"
print(storage["foo"]); // "bar"
print(service["foo"].runtimeType); // "String"
print(service["foo"]); // "bar"

print(storage.getObject("baz").runtimeType); // "_JsonMap"
print(storage.getObject("baz")); // {"qux": 123}
print(storage.getObject("baz")["qux"]); // 123
print(service.getObject("baz").runtimeType); // "_JsonMap"
print(service.getObject("baz")); // {"qux": 123}
print(service.getObject("baz")["qux"]); // 123

// Iterate the storage.
for (final entry in service.entries) print("${entry.key} => ${entry.value}");

// Delete from the storage.
storage.remove("foo");
print(storage.containsKey("foo")); // false
print(storage.length); // 1
print(storage.keys); // ["baz"]
service.remove("foo");
print(service.containsKey("foo")); // false
print(service.length); // 1
print(service.keys); // ["baz"]

storage.clear();
print(storage.containsKey("baz")); // false
print(storage.isEmpty); // true
print(storage.keys); // []
service.clear();
print(service.containsKey("baz")); // false
print(service.isEmpty); // true
print(service.keys); // []

// Release the event listeners.
storage.destroy();
service.destroy();
}

Loading…
Cancel
Save