0
0
Fluttermobile~10 mins

Realtime Database in Flutter - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the Firebase Realtime Database instance.

Flutter
final database = FirebaseDatabase.instance[1];
Drag options to blanks, or click blank then click option'
A.initialize()
B.connect()
C.start()
D.ref()
Attempts:
3 left
💡 Hint
Common Mistakes
Using .initialize() instead of .ref()
Trying to call .connect() which does not exist
2fill in blank
medium

Complete the code to write data to the 'users' node in the database.

Flutter
database.ref('users').[1]({'name': 'Alice', 'age': 25});
Drag options to blanks, or click blank then click option'
Aget
Bupdate
Cset
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' which reads data instead of writing
Using 'remove' which deletes data
3fill in blank
hard

Fix the error in the code to listen for realtime updates on the 'messages' node.

Flutter
database.ref('messages').on[1]((event) {
  final data = event.snapshot.value;
  print(data);
});
Drag options to blanks, or click blank then click option'
Avalue
Bchange
Cupdate
Dchild_added
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'onChange' which is not a valid event
Using 'onChildAdded' which listens only for new child nodes
4fill in blank
hard

Fill both blanks to update the 'status' field to 'online' for user with id 'user123'.

Flutter
database.ref('users/[1]').[2]({'status': 'online'});
Drag options to blanks, or click blank then click option'
Auser123
Bset
Cupdate
DuserId
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' which overwrites all data at the path
Using a variable name instead of the actual user ID string
5fill in blank
hard

Fill all three blanks to remove the 'age' field from user 'user456'.

Flutter
database.ref('users/[1]').[2]({'[3]': null});
Drag options to blanks, or click blank then click option'
Auser456
Bupdate
Cage
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' which overwrites all data
Trying to remove the field by deleting the whole user node