Book Image

DART Cookbook

By : Ivo Balbaert
Book Image

DART Cookbook

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Dart Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Storing data locally with IndexedDB


IndexedDB is a more robust client-side storage mechanism than local storage in a browser. Likewise, it provides offline capabilities and is based on saving and retrieving data as key-value pairs, but it lets you store significantly bigger amounts of data and allows for high performance searching using database keys. IndexedDB is supported in modern browsers, but is only partially supported in Internet Explorer above Version 10 (refer to http://caniuse.com/#feat=indexeddb for details).

How to do it...

You can find the code for this recipe in the using_indexeddb project. We use the same method from the Posting JSON-formatted data recipe in Chapter 7, Working with Web Servers, but now we only store the data locally in IndexedDB. The following is the relevant code from using_indexeddb.dart:

import 'dart:indexed_db';

void main() {
  //test if browser supports IndexedDB:
  if (!IdbFactory.supported) {
    window.alert("Sorry, this browser does not support IndexedDB...