localstorage 3.0.0+2 localstorage: ^3.0.0+2 copied to clipboard
Simple json file-based storage fo flutter. Alternative to react-native AsyncStorage
Localstorage #
Simple json file-based storage for flutter
Installation #
Add dependency to pubspec.yaml
dependencies:
...
localstorage: ^3.0.0
Run in your terminal
flutter packages get
Example #
class SomeWidget extends StatelessWidget {
final LocalStorage storage = new LocalStorage('some_key');
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: storage.ready,
builder: (BuildContext context, snapshot) {
if (snapshot.data == true) {
Map<String, dynamic> data = storage.getItem('key');
return SomeDataView(data: data);
} else {
return SomeLoadingStateWidget();
}
},
);
}
}
Desktop support #
In order to be able to use this package on desktop, add this to your pubspec.yaml
dependencies:
localstorage: ^3.0.0
path_provider_fde:
git:
url: https://github.com/google/flutter-desktop-embedding/
path: plugins/flutter_plugins/path_provider_fde
Integration tests #
cd ~/flutter_localstorage/test
flutter packages get
flutter drive --target=lib/main.dart
License #
MIT