indexedDb can save only Map type. The limitation is not described in Dart API. #17371
Labels
area-core-library
SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
closed-obsolete
Closed as the reported issue is no longer relevant
docs-api
library-html
P3
A lower priority bug or feature request
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
This issue was originally filed by igor.ko...@mailvision.com
indexedDB can store object in Map form, but cannot store object instance.
The limitation is not described in dart API.
What steps will reproduce the problem?
start the Web program (as dart or as javascript), and see console log.
------------ web application ------------------------
import 'dart:html';
import 'dart:indexed_db';
class Record {
List<int> data;
String str;
double value;
Record(this.data, this.str, this.value);
Map toMap()=>{"data":data, "str":str, "value":value };
}
void main(){
Record record = new Record([1,2,3], "Hello", 5.7);
Database db;
IdbFactory idb = window.indexedDB;
idb.open("test_db", version: 1, onUpgradeNeeded: onUpgradeNeeded)
.then((Database v){
db = v;
})
.then((){
print("put1");
Transaction trn = db.transaction("store_one", "readwrite");
ObjectStore st = trn.objectStore("store_one");
return st.put(record.toMap(), "key1"); /// It's OK.
})
.then((){
print("put2");
Transaction trn = db.transaction("store_one", "readwrite");
ObjectStore st = trn.objectStore("store_one");
return st.put(record, "key2"); /// !!!!!!!!!!!!! Exception !!!!!!!!!!!!!!
});
}
void onUpgradeNeeded(VersionChangeEvent vce){
print("onUpgradeNeeded");
Database db = (vce.target as OpenDBRequest).result;
if( vce.oldVersion == 0 ){
db.createObjectStore("store_one");
}
}
--------------- console log (dartium) ------------------------------
put1
put2
Uncaught Error: unsupported object type for conversion
As you can see in console log, or checking result DB in Chrome dev tools/resources:
data in Map form successfully inserted,
the same data throw exception, then put() called with class instance.
The text was updated successfully, but these errors were encountered: