Skip to content

Instantly share code, notes, and snippets.

@timtraversy
Last active September 23, 2021 14:14
Show Gist options
  • Save timtraversy/d663ef1e37c2a8c49437c76be7062e85 to your computer and use it in GitHub Desktop.
Save timtraversy/d663ef1e37c2a8c49437c76be7062e85 to your computer and use it in GitHub Desktop.
Using localStorage with Flutter for web
@JS()
library storage;
import 'package:js/js.dart';
external Storage get localStorage;
@JS()
class Storage {
int length;
external dynamic getItem(String key);
external void setItem(String key, dynamic item);
external void removeItem(String key);
external void clear();
}
main() {
localStorage.setItem('foo', 'bar');
print(localStorage.length); // 1
print(localStorage.getItem('foo')); // 'bar'
localStorage.removeItem('foo');
print(localStorage.length); // 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment