Storage class

The type used by the Window.localStorage and Window.sessionStorage properties. Storage is implemented as a Map<String, String>.

To store and get values, use Dart's built-in map syntax:

window.localStorage['key1'] = 'val1';
window.localStorage['key2'] = 'val2';
window.localStorage['key3'] = 'val3';
assert(window.localStorage['key3'] == 'val3');

You can use Map APIs such as containsValue(), clear(), and length:

assert(window.localStorage.containsValue('does not exist') == false);
window.localStorage.clear();
assert(window.localStorage.length == 0);

For more examples of using this API, see localstorage_test.dart. For details on using the Map API, see the Maps section of the library tour.

Inheritance
Implements
Annotations
  • @DomName('Storage')
  • @Unstable()

Static Properties

instanceRuntimeTypeType
@Deprecated("Internal Use Only"), read-only

Constructors

Storage.internal_()

Properties

isEmptybool
read-only
isNotEmptybool
read-only
keysIterable<String>
read-only
lengthint
read-only
valuesIterable<String>
read-only
hashCodeint
read-only, inherited
runtimeTypeType
read-only, inherited

A representation of the runtime type of the object.

Operators

operator [](Object key) → String

Returns the value for the given key or null if key is not in the map.

operator []=(String key, String value) → void

Associates the key with the given value.

operator ==(other) → bool
inherited

The equality operator.

Methods

addAll(Map<String, String> other) → void

Adds all key-value pairs of other to this map.

clear() → void

Removes all pairs from the map.

containsKey(Object key) → bool

Returns true if this map contains the given key.

containsValue(Object value) → bool

Returns true if this map contains the given value.

forEach(void f(String key, String value)) → void

Applies f to each key-value pair of the map.

putIfAbsent(String key, String ifAbsent()) → String

Look up the value of key, or add a new value if it isn't there.

remove(Object key) → String

Removes key and its associated value, if present, from the map.

noSuchMethod(Invocation invocation) → dynamic
inherited

Invoked when a non-existent method or property is accessed.

toString() → String
inherited

Returns the result of the JavaScript objects toString method.

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-html/Storage-class.html