Book Image

Learning Dart, Second Edition - Second Edition

By : Ivo Balbaert
Book Image

Learning Dart, Second Edition - Second Edition

By: Ivo Balbaert

Overview of this book

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

Using Lawndart


IndexedDB doesn't (yet) work on all browsers. What if we don't know what browser our 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 Store class 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() async {
    await for (var taskJsonString in _store.all()) {
      var task = new Task();
      task.fromJsonString(taskJsonString);
      tasks.add(task);
    } 
}

Study lawndart.dart to see...