simple_database 1.0.4

Flutter Android iOS web

A simple lightweight wrapper for the SharedPreferences Flutter package.

Simple Database #

CI codecov

A simple lightweight wrapper for the SharedPreferences Flutter package. Simple Database provides an abstraction layer for storing objects instead of key, value pairs. This makes it very easy to get a quick local storage solution up and running.

GitHub #

Please feel free to contribute

Usage #

Please add simple_database as a dependency in your pubspec.yaml file

Non-Primitive object storage #

You can store your own objects you have created easily just by implementing 2 functions in the class. toJson and fromJson. You will need to pass the fromJson function to the constructor of SimpleDatabase if you want it to rebuild the json into your object. You do not need this, it will just return a hash map with the values from your object if the function is not provided.


class SimpleClass {
  final int age;
  final String name;
  final double height;
  final bool gender;

  SimpleClass(this.age, this.name, this.height, this.gender);

  //Implement fromJson - Required
  SimpleClass.fromJson(Map<String, dynamic> json) : age = json['age'], name = json['name'], height = json['height'], gender = json['gender'];

  //Implement toJson - Required
  Map<String, dynamic> toJson() => {
    'age': age,
    'name' : name,
    'height' : height,
    'gender' : gender,
  };
}

void main() async {
    SimpleDatabase classDB = SimpleDatabase(name: 'class', fromJson: (fromJson) => SimpleClass.fromJson(fromJson));

    SimpleClass john = SimpleClass(18, 'John', 5.2, true);  

    await classDB.add(john);

    dynamic person = await classDB.getAt(0);
    print(person.name);
}

TODO: #

  • Built in encryption of stored json strings
  • Better documentation
3
likes
100
pub points
44%
popularity

A simple lightweight wrapper for the SharedPreferences Flutter package.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

griffinq178@gmail.com

License

BSD (LICENSE)

Dependencies

flutter, shared_preferences

More

Packages that depend on simple_database