Last active
September 20, 2015 08:16
-
-
Save EasonPai/537f9c839ae7b5f4095a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void firebase_demo() { | |
| // creating a firebase database reference | |
| Firebase firebaseRef = new Firebase("https://lab-of-pai.firebaseio.com/"); | |
| // writing data | |
| firebaseRef.set({"hello": "world"}).then((_) { | |
| // after data is set | |
| print("after data is set"); | |
| }); | |
| // adding data | |
| firebaseRef.push(value: {"hi": "dart"}, onComplete: (err) { | |
| print("err = ${err}"); | |
| }); | |
| // updating data | |
| firebaseRef.update({"hello": "firebase"}).then((_) { | |
| // after data is updated | |
| print("after data is updated"); | |
| }); | |
| // retrieve data | |
| firebaseRef.once("value").then((DataSnapshot result) { | |
| print("once result = ${result.val()}"); | |
| }); | |
| firebaseRef.onValue.listen((event){ | |
| print("onValue event = ${event.snapshot.val()}"); | |
| }); | |
| // retrieve data | |
| firebaseRef.once("child_changed").then((DataSnapshot result) { | |
| print("child_changed result = ${result.val()}"); | |
| }); | |
| firebaseRef.onChildAdded.listen((event){ | |
| print("onChildAdded event = ${event.snapshot.val()}"); | |
| }); | |
| firebaseRef.onChildChanged.listen((event){ | |
| print("onChildChanged event = ${event.snapshot.val()}"); | |
| }); | |
| firebaseRef.onChildRemoved.listen((event){ | |
| print("onChildChanged event = ${event.snapshot.val()}"); | |
| }); | |
| // adding data | |
| firebaseRef.push(value: {"hi": "developer"}); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // creating a firebase database reference | |
| Firebase firebaseRef = new Firebase("https://lab-of-pai.firebaseio.com/"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // writing data | |
| firebaseRef.set({"hello": "world"}).then((_) { | |
| // after data is set | |
| print("after data is set"); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment