All Projects → bartektartanus → pref_dessert

bartektartanus / pref_dessert

Licence: BSD-3-Clause License
Package that allows you persist objects as shared preferences easily.

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to pref dessert

Android-SharedPreferences-Helper
This Shared Preferences Helper library (Library size = ~15kb only) Simplifies usage of the default Android SharedPreferences Class. The developer can do in a few lines of code which otherwise would have required several. Simple to understand as compared to the default Shared Preferences class and easy to use. Can be used by simply adding the dep…
Stars: ✭ 15 (+25%)
Mutual labels:  sharedpreferences
ElegantData
像操作Room一样操作 SharedPreferences 和 File 文件.
Stars: ✭ 18 (+50%)
Mutual labels:  sharedpreferences
RemotePreferences
A drop-in solution for inter-app access to SharedPreferences.
Stars: ✭ 121 (+908.33%)
Mutual labels:  sharedpreferences
fit
easy storage Object on SharedPreferences
Stars: ✭ 53 (+341.67%)
Mutual labels:  sharedpreferences
kesho
store cache any data type string, boolean, jsonObject, jsonArray, .....
Stars: ✭ 19 (+58.33%)
Mutual labels:  sharedpreferences
KVStorage
Android 结构化KV存储框架,基于 yaml 生成 java 结构化存储类
Stars: ✭ 228 (+1800%)
Mutual labels:  sharedpreferences
Serialize
🍒 Android 简单高性能读写本地数据, 直接存储对象/基础类型
Stars: ✭ 181 (+1408.33%)
Mutual labels:  sharedpreferences
ToDoApp
📱My android playground app - Simple and Fastest todo app - developing to cover most android concepts, simple logic can make me focus more on framework
Stars: ✭ 28 (+133.33%)
Mutual labels:  sharedpreferences
DailyBugle
📰Modern MVVM Android application following single activity architecture which fetches news from 🕷️ news API. this repository contains some best practices ⚡ of android development
Stars: ✭ 17 (+41.67%)
Mutual labels:  sharedpreferences
preferx
A reactive SharedPreferences library for Kotlin
Stars: ✭ 13 (+8.33%)
Mutual labels:  sharedpreferences
PowerPreference
💾 A Powerful library to control and simplify the usage of shared preference in Android.
Stars: ✭ 95 (+691.67%)
Mutual labels:  sharedpreferences
simple-preferences
Android Library to simplify SharedPreferences use with code generation.
Stars: ✭ 48 (+300%)
Mutual labels:  sharedpreferences
iMoney
iMoney 金融项目
Stars: ✭ 55 (+358.33%)
Mutual labels:  sharedpreferences
CipherSharedPrefs
Library implements encrypion layer for SharedPreferences. Also adds some additional features
Stars: ✭ 15 (+25%)
Mutual labels:  sharedpreferences
Quiz-App
A Quiz Android application 📱 built using Java ♨️ and showing best practices of 🛠️ Room
Stars: ✭ 33 (+175%)
Mutual labels:  sharedpreferences
Awesome-Android-Persistence
A curated list of awesome android persistence libraries about SQLite, ORM, Mobile Database, SharedPreferences, etc.
Stars: ✭ 69 (+475%)
Mutual labels:  sharedpreferences
shade
Automatic code generation for the SharedPreferences operation.
Stars: ✭ 26 (+116.67%)
Mutual labels:  sharedpreferences
Yasp
Yet Another Shared Preference
Stars: ✭ 16 (+33.33%)
Mutual labels:  sharedpreferences
memo
Android processing and secured library for managing SharedPreferences as key-value elements efficiently and structurally.
Stars: ✭ 18 (+50%)
Mutual labels:  sharedpreferences
Preference-Rhythm
Android library makes using Shared Preference easier.
Stars: ✭ 16 (+33.33%)
Mutual labels:  sharedpreferences

pref_dessert

pub package Build Status codecov

Package that allows you persist objects as shared preferences easily. Package name comes from: Shared PREFerences DESerializer/SERializer of T (generic) class.

Getting Started

To use this package you just need to extend DesSer<T> class, replace generic T class with the one you want to save in shared preferences. This class requires you to implement two methods to serialize and deserialize objects. In future releases I'm planning to use JSON serializer so it will be much simpler to use. Then pass this class to PreferenceRepository or FuturePreferencesRepository and you're good to go!

Example

Person class that you want to serialize:

class Person {
  String name;
  int age;

  Person(this.name, this.age);
}

PersonDesSer which extends DesSer<T> and implements two methods which serialize this objects using CSV format:

class PersonDesSer extends DesSer<Person>{
  @override
  Person deserialize(String s) {
    var split = s.split(",");
    return new Person(split[0], int.parse(split[1]));
  }

  @override
  String serialize(Person t) {
    return "${t.name},${t.age}";
  }
  
}

You can also do this using JSON with convert package:

import 'dart:convert';

class JsonPersonDesSer extends DesSer<Person>{
  @override
  Person deserialize(String s) {
    var map = json.decode(s);
    return new Person(map['name'] as String, map['age'] as int);
  }

  @override
  String serialize(Person t) {
    var map = {"name":t.name, "age":t.age};
    return json.encode(map);
  }

}

Then create an instance of either class and pass it to the FuturePreferencesRepository<T>:

var repo = new FuturePreferencesRepository<Person>(new PersonDesSer());
repo.save(new Person("FooBar", 42));
var list = repo.findAll();

Using json_serializable package to generate DesSer

Step 1: import library json_serializable. in pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  pref_dessert: ^0.4.0+1
  json_serializable: ^3.2.2
  json_annotation: ^3.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner: ^1.0.0

Step 2: Create your class with annotation @JsonSerializable

import 'package:pref_dessert/pref_dessert.dart';
import 'package:json_annotation/json_annotation.dart';

part 'user.g.dart';

@JsonSerializable()
class User {
  String uid = "";
  String photoUrl = "";
  String displayName = "";
  String email = "";

  User({this.uid, this.photoUrl, this.displayName, this.email});
}

class UserDesSer extends JsonDesSer<User> {
  @override
  String get key => "PREF_USER";

  @override
  User fromMap(Map<String, dynamic> map) => _$UserFromJson(map);

  @override
  Map<String, dynamic> toMap(User user) => _$UserToJson(user);
}

Step 3: Run command : flutter pub run build_runner build

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].