madob 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 60

Madob #

Madob is a super simple and easy to use highly-asynchronous library for database-synchronized objects. It is built upon hive, the blazing-fast key-value database. It handles all database-related stuff under the hood and appears as a fast sports car. Just access your variables with get and set() as you are used to.

Use cases #

Madob is used to keep data persistent and synchronized across instances by a single Id. Let my explain this with a simple example:

We have some App-Settings we want to keep persistent. For that we just create a new MadobType and let the code generator do the job for us:

@MadobType(typeId: 2)
abstract class ISettings implements IKey {
  String get managedKey;

  Future<bool> get runAppBugFree;

  Future<void> setRunAppBugFree(bool value);

After code generation we can load and store settings like this:

var settings = ManagedSettings();
await settings.initialize(() => Settings('appSettings'));

var currentValue = (await settings.runAppBugFree) ?? false;
print('Run app bug free: $currentValue');

await settings.setRunAppBugFree(!currentValue);

After each run/start of our example, runAppBugFree is getting negated and therefor the app is always with a chance of 50% bug-free :). The complete code is available here.

Also take a look at a more comprehensive example here.

Madob changelog #

0.1.2 #

  • Improved documentation and examples

0.1.1 #

  • Added madob_generator to generate examples

0.1.0 #

  • Initial release


import 'package:madob/madob.dart';

import 'data/objects/project.dart';
import 'data/objects/task.dart';
import 'helper/path_provider.dart';

void main() async {
  // Directory to store the box(-files) in
  final directory = await PathProvider().getTempDirectory();

  // Register our adapter and define the box name
  // where eveything is going to be saved in
  BoxRepository.register('projectBox', ProjectAdapter());
  BoxRepository.register('taskBox', TaskAdapter());

  // Generate two unique Id's
  final taskid = StrongUuid().generate();
  final projectId = StrongUuid().generate();

  print('Id for Task: $taskid');
  print('Id for Project: $projectId');

  // Create a new Task and initialize it with the generated Id
  final task = ManagedTask();
  await task.initialize(() => Task(taskid));

  // Create a Project and directly assign it to our Task
  await task.setProject(Project(projectId));

  // Create a duplicate instance of Project at thsi point,
  // to proof sync via projectId later
  final project = ManagedProject();
  await project.initialize(() => Project(projectId));

  // Just perform a simple get/set operation
  await task.setTitle('Test Task');
  print('After .setTitle(): ${await task.title}');

  // Close both boxes to free ressources or simulate an app close
  await BoxRepository.closeBox<Task>();
  await BoxRepository.closeBox<Project>();

  // Set title through closed task
  await (await task.project).setTitle('Test Project');
  // Just mix things up and replace the underlying Project instance
  await task.setProject(project);

  // Close the handle
  await BoxRepository.closeBox<Project>();

  // create a new instance of Project with our defined Id
  final regainedProject = ManagedProject();
  await regainedProject.initialize(() => Project(projectId));

  // Let's see if everything keeps synchronized:
  print('title of project set through task: ${await regainedProject.title}');
  print('title of project through untouched instance: ${await project.title}');
  print('title of project through task: ${await (await task.project).title}');

Use this package as a library

1. Depend on it

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

  madob: ^0.1.2

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:madob/madob.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 Jun 5, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
hive ^1.3.0 1.4.1+1
meta ^1.1.8 1.1.8
uuid ^2.0.4 2.0.4
Transitive dependencies
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.5
typed_data 1.1.6
Dev dependencies
build_runner ^1.7.2
effective_dart ^1.2.1
hive_generator ^0.7.0
madob_generator ^0.2.3
mockito ^4.1.1
pedantic ^1.8.0
test ^1.6.0