pub package Build Status

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!


Person class that you want to serialize:

class Person {
  String name;
  int age;

  Person(, this.age);

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

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

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

You can also do this using JSON with convert package:

import 'dart:convert';

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

  String serialize(Person t) {
    var map = {"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()); Person("FooBar", 42));
var list = repo.findAll();

Using json_serializable package to generate DesSer

Step 1: import library json_serializable. in pubspec.yaml

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

    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';

class User {
  String uid = "";
  String photoUrl = "";
  String displayName = "";
  String email = "";

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

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

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

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

Step 3: Run command : flutter pub run build_runner build





Foreign Function Interface for interoperability with the C programming language. [...]


HTML elements and other resources for web-based applications that need to interact with the browser and the DOM (Document Object Model). [...]
Low-level support for interoperating with JavaScript. [...]
Utility methods to efficiently manipulate typed JSInterop objects in cases where the name to call is not known at runtime. You should only use these methods when the same effect cannot be achieved with @JS annotations. These methods would be extension methods on JSObject if Dart supported extension methods.