pref_dessert 0.8.0 copy "pref_dessert: ^0.8.0" to clipboard
pref_dessert: ^0.8.0 copied to clipboard

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

example/lib/main.dart

import 'package:pref_dessert/pref_dessert.dart';

/// 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}";
  }

  @override
  String get key => "Person";

}

void main() {
  var repo = new FuturePreferencesRepository<Person>(new PersonDesSer());
  repo.save(new Person("Foo", 42));
  repo.save(new Person("Bar", 1));
  var list = repo.findAll();
  print(list);
}
10
likes
130
pub points
68%
popularity

Publisher

verified publisherkonwencik.pl

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter, json_annotation, shared_preferences

More

Packages that depend on pref_dessert