Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if node exists in Firebase Database with Flutter/Dart

I've seen this question answered multiple times already for JavaScript and other languages. There, it always comes down to get a snapshot and use a method called exists() to check. But in Dart/Flutter, there is no such method. Here's what I have for now:

devicesRef.child(deviceId).once().then((DataSnapshot data) {
    print(data.key);
    print(data.value);        
});

I want to check whether a node called deviceId already exists.

So how can I check if a node exists in Firebase Realtime Database with Dart/Flutter?

like image 305
Stephan Avatar asked Jan 28 '23 01:01

Stephan


1 Answers

I would guess, since there is no such thing as a null child value in Realtime Database, that you could simply check if data.value is null.

like image 82
Doug Stevenson Avatar answered Feb 01 '23 18:02

Doug Stevenson