Cannot add dart objects to Firebase-Collection data
I have simple PODO like
class Todo{
String title;
bool isComplete;
Todo();
Todo.basic(this.title,this.isComplete);
}
Html:
<firebase-collection id="firebase" log="true"
location="{{location}}"
data="{{todos}}"></firebase-collection>
Dart:
@reflectable
AddNew(Event e,Object o){
add('todos',new Todo.basic("new todo",false));
}
When I add new Todo object to todos List, new item not send to firebase.
As workaround you can try:
add('todos',convertToJs(new Todo.basic("new todo",false)));
Above solution is not working. convertToJs return an Js object.
Is it possible to convert Dart Object to Map in polymer? If i add map to firebase-collection, it gets updated in firebase.
I think this caused by https://github.com/dart-lang/polymer-dart/issues/618. As long as your class extends JsProxy then it should work once that issue is fixed.
Thanks @jakemac53 . I tried with extending JsProxy and using JsProxy as Mixin. Both ways not solving the issue.
here is my dart Todo class PODO - Case1:
class Todo extends JsProxy{
String title;
bool isComplete;
Todo();
Todo.basic(this.title,this.isComplete);
}
PODO - Case2:
class Todo extends Object with JsProxy{
String title;
bool isComplete;
Todo();
Todo.basic(this.title,this.isComplete);
}
The fields should also be annotated with @reflectable
Yes @zoechi. You are right I need to add @reflectable annotation to fields.
Still I am not able to send todo object to firebase. I can see that convertToJs function returns JsObjectImpl object.
here is my dart Todo class PODO - Case2:
class Todo extends Object with JsProxy{
@reflectable
String title;
@reflectable
bool isComplete;
Todo();
Todo.basic(this.title,this.isComplete);
}
add(){
var _todo = convertToJs(new Todo.basic("new todo",false));
print('Todo Title : ${_todo['title']}');
add('todos',_todo);
}
Chromium Console:
Todo Title :new todo
Adding new item to collection with value: Object {__dartClass__: DartObject}__dartClass__: DartObject
isCompleted: false
priority: ""
title: "vimal"
__proto__: Object
When I checked Firebase data not updated !
As mentioned above even with JsProxy it won't work because of dart-lang/polymer-dart#618