Book Image

Learning Dart

Book Image

Learning Dart

Overview of this book

Table of Contents (19 chapters)
Learning Dart
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Using IndexedDB with Dart


We will learn how to work with IndexedDB and JSON web services through the indexed_db_spirals project (https://github.com/dzenanr/indexed_db_spirals), which is a todo app like the ones we've built in previous chapters, but that stores its data in IndexedDB. Get a copy of the code with a git clone:https://github.com/dzenanr/indexed_db_spirals.git.

Spiral s00

In this spiral, todo tasks can be entered, and they are stored in IndexedDB; the following is a screenshot:

The Tasks screen of Spiral s00

Our model class is called Task, and lives in model.dart; with toDb and fromDb, it can transform an object to or make an object from a map:

class Task {
  String title;
  bool completed = false;
  DateTime updated = new DateTime.now();
  var key;

  Task(this.title);

  Task.fromDb(this.key, Map value):
    title = value['title'],
    updated = DateTime.parse(value['updated']),
    completed = value['completed'] == 'true' {
  }

  Map toDb() {
    return {
      'title': title...