local_database 1.1.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 69

A local database using dart:io file system components

Getting started #

In the pubspec.yaml of your flutter project, add the following dependency:

  local_database: ^1.1.0+1

In your library add the following import:

import "package:local_database/local_database.dart";

For help getting started with Flutter, view the online documentation.

Using #

This plugin comes with three main operations, get, put, and remove.

To use the database, simply instantiate it with the constructor Database database = new Database(/*File System Path to database*/);

Next, call the built in methods for database.

To put into the database, use the []= operator (note that only JSON encodable types can be used). The parameter of this operator is the path in the database to put to delimited by forward slashes ("/").

database["dir1"] = {
database["dir1/b/0"] = 100;

To read from the database, use the [] operator. The parameter of this operator is the path in the database to read from delimited by forward slashes ("/").

print(await database["dir1"]);
print(await database["dir1/b/0"]);

To remove from the database, use the .remove(String path) method. The parameter of this operator is the path in the database to put to delimited by forward slashes ("/").


The following is an example use of the package:

Database database = new Database(Directory.current.path+"/data");
Map<String,dynamic> userData;
if((await database["userData"])==null){
	String userId = "";
	Random r = new Random();
	for(int i = 0; i<8;i++){
	database["userData"] = {
		"created": (new DateTime.now()).millisecondsSinceEpoch,
userData = await database["userData"];

1.1.0+1 #

  • Fixed typos

1.1.0 #

  • Reading is now asynchronous
  • Removing now returns void

1.0.1+4 #

  • Readme fixes

1.0.1+3 #

  • Fixed a typo in readme

1.0.1+2 #

  • Fixed changelog

1.0.1+1 #

  • Fixed a bug with getting from root when it is empty

1.0.1 #

  • Removed static method fromApplicationDocumentsDirectory

1.0.0+2 #

  • Readme fixes

1.0.0 #

  • Initial release


import "dart:io";
import "package:local_database/local_database.dart";

void main() async {
  String home = "";
  Map<String, String> envVars = Platform.environment;
  if (Platform.isMacOS) {
    home = envVars["HOME"];
  } else if (Platform.isLinux) {
    home = envVars["HOME"];
  } else if (Platform.isWindows) {
    home = envVars["UserProfile"];
  } else {
    throw new Exception("Unknown platform");
  Database database = new Database(home + "/data");
  //Put a complex map into path /dir1
  database["dir1"] = {
    "a": [1, 2, 3],
    "b": {"c": 5},
    "d": [
      {"e": 5}
  //Put a single string into path /dir2/f
  database["dir2/f"] = "Data";
  //Read from /dir1
  print(await database["dir1"]);
  //Read from /dir1/a/0
  print(await database["dir1/a/0"]);
  //Read the entire database
  print(await database["/"]);
  //Read a nonexistent element
  print(await database["nonexistant"]);
  //Remove from the database
  print(await database["dir1"]);
  new Directory(home + "/data")..deleteSync(recursive: true);

Use this package as a library

1. Depend on it

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

  local_database: ^1.1.0+1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:

import 'package:local_database/local_database.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Mar 30, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies