pref_dessert 0.0.6

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new74

pref_dessert

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();

0.0.6

  • added example and more comments in code

0.0.5

  • tests bug fix

0.0.4

  • There are now two repository classes - 'normal' and Future version
  • Added more methods to repository classes
  • DesSer<T> class for DESserializing and SERializing classes instead of two abstract methods in PreferencesRepository

0.0.2

  • Better description with example
  • Test for class serialization with json.

0.0.1

  • First version

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

}

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();

}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  pref_dessert: "^0.0.6"

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


      import 'package:pref_dessert/pref_dessert.dart';
  
Version Uploaded Documentation Archive
0.0.6 Jul 16, 2018 Go to the documentation of pref_dessert 0.0.6 Download pref_dessert 0.0.6 archive
0.0.5 Jul 4, 2018 Go to the documentation of pref_dessert 0.0.5 Download pref_dessert 0.0.5 archive
0.0.4 Jul 4, 2018 Go to the documentation of pref_dessert 0.0.4 Download pref_dessert 0.0.4 archive
0.0.3 Jun 27, 2018 Go to the documentation of pref_dessert 0.0.3 Download pref_dessert 0.0.3 archive
0.0.2 Jun 23, 2018 Go to the documentation of pref_dessert 0.0.2 Download pref_dessert 0.0.2 archive
0.0.1 Jun 23, 2018 Go to the documentation of pref_dessert 0.0.1 Download pref_dessert 0.0.1 archive

Analysis

We analyzed this package on Jul 16, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3
  • Flutter: 0.5.4

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
50 / 100
Health:
Code health derived from static analysis. [more]
99 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
74
Learn more about scoring.

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 hint.

    Run flutter format to format lib/pref_dessert.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.54 <3.0.0
flutter 0.0.0
json_annotation ^0.2.0 0.2.9
shared_preferences ^0.4.0 0.4.2
Transitive dependencies
collection 1.14.6 1.14.10
meta 1.1.5
sky_engine 0.0.99
typed_data 1.1.5
vector_math 2.0.6 2.0.7
Dev dependencies
build_runner ^0.8.9
flutter_driver
flutter_test
json_serializable ^0.5.0
test ^0.12.40