Last active
September 23, 2021 14:14
-
-
Save timtraversy/d663ef1e37c2a8c49437c76be7062e85 to your computer and use it in GitHub Desktop.
Using localStorage with Flutter for web
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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