Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marchdev-tk/cross_local_storage
SharedPreferences wrapper for both Mobile (Android/iOS), Web and Desktop (Windows, macOS, Linux).
https://github.com/marchdev-tk/cross_local_storage
android dart dart2 dartlang flutter flutter-package flutter-plugin ios linux localstorage macos macosx nsuserdefaults shared-preferences sharedpreferences storage userdefaults web windows
Last synced: 4 months ago
JSON representation
SharedPreferences wrapper for both Mobile (Android/iOS), Web and Desktop (Windows, macOS, Linux).
- Host: GitHub
- URL: https://github.com/marchdev-tk/cross_local_storage
- Owner: marchdev-tk
- License: bsd-3-clause
- Created: 2020-03-10T17:30:46.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-09-27T20:47:05.000Z (over 1 year ago)
- Last Synced: 2024-10-01T16:39:58.266Z (4 months ago)
- Topics: android, dart, dart2, dartlang, flutter, flutter-package, flutter-plugin, ios, linux, localstorage, macos, macosx, nsuserdefaults, shared-preferences, sharedpreferences, storage, userdefaults, web, windows
- Language: C++
- Homepage:
- Size: 361 KB
- Stars: 10
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# cross_local_storage
![Build](https://github.com/marchdev-tk/cross_local_storage/workflows/build/badge.svg)
[![Pub](https://img.shields.io/pub/v/cross_local_storage.svg)](https://pub.dartlang.org/packages/cross_local_storage)
![GitHub](https://img.shields.io/github/license/marchdev-tk/cross_local_storage)
![GitHub stars](https://img.shields.io/github/stars/marchdev-tk/cross_local_storage?style=social)Wraps NSUserDefaults (on iOS and macOS), SharedPreferences (on Android), LocalStorage (on Web) and JSON file (on Windows and Linux), providing a persistent store for simple data.
Data is persisted to disk asynchronously.
Neither platform can guarantee that writes will be persisted to disk after returning and this plugin must not be used for storing critical data.## Getting Started
In order to use this plugin, add dependency in the `pubspec.yaml`:
```yaml
cross_local_storage: any
```or
```yaml
cross_local_storage:
git:
url: https://github.com/marchdev-tk/cross_local_storage
```Add an import to dart file:
```dart
import 'package:cross_local_storage/cross_local_storage.dart';
```### Example
```dart
import 'package:flutter/material.dart';
import 'package:cross_local_storage/cross_local_storage.dart';void main() {
runApp(MaterialApp(
home: Scaffold(
body: Center(
child: RaisedButton(
onPressed: _incrementCounter,
child: Text('Increment Counter'),
),
),
),
));
}_incrementCounter() async {
LocalStorageInterface prefs = await LocalStorage.getInstance();
int counter = (prefs.getInt('counter') ?? 0) + 1;
print('Pressed $counter times.');
await prefs.setInt('counter', counter);
```## Feature requests and Bug reports
Feel free to post a feature requests or report a bug [here](https://github.com/marchdev-tk/cross_local_storage/issues).