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 Lawndart


IndexedDB doesn't (yet) work on all browsers. What if you don't know what browser your clients will use? Can we still provide universal offline key-value storage? The solution is Lawndart (https://github.com/sethladd/lawndart), a pub package that you can import in your app, which has been developed by Seth Ladd as a Dart reworking of Lawnchair. Lawndart presents an asynchronous, but consistent, interface to local storage, IndexedDb, and Web SQL. Your app simply works with an instance of the class Store and the factory constructor will try IndexedDB, Web SQL, and then, finally, local storage. This is implemented in Spiral s05_1; the only change with Spiral s05 is that IndexedDB (idb.dart) is replaced with Lawndart (lawndart.dart). For example, the load method is now written as:

Future load() {
    Stream dataStream = _store.all();
    return dataStream.forEach((taskMap) {      
      var task = new Task.fromDb(taskMap);
      tasks.add(task);
    });
}
Study lawndart.dart to...