0

I have the following Firebase realtime database connected to my flutter project:

enter image description here

I am fairly new to flutter and firebase, I understand that a way to access the data in this database in my flutter project is by using a database reference variable. So i have the following reference variable itemRef:

class _MyHomePageState extends State<MyHomePage> {
  DatabaseReference itemRef;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    itemRef = FirebaseDatabase.instance.reference();
  }

Now, how do i access the temperature and pulse values in the database using this itemRef?

0

1 Answer 1

1

Try the following:

itemRef = FirebaseDatabase.instance.reference();
itemRef.once().then((DataSnapshot snapshot){
  print(snapshot.value);
  var pulse = snapshot.value["pulse"];
  var temp  = snapshot.value["temperature"];
});

use the once() method to retrieve the data, then snapshot.value will be of type Map<String,dynamic> and you can access the attributes using the get operator.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.