skip to Main Content

enter image description here

this is the problem.

I want to use realtime database with firebase and this problem is preventing me.
I think I’m using the old technique.

2

Answers


  1. The code snippet in the image shows an older way to connect to Firebase Realtime Database.

    Here’s what you can do to update it:

    Create a DatabaseReference:

    Get a reference to the location in your database where you want to store or retrieve data:

    final database = FirebaseDatabase.instance;
    final myRef = database.reference().child("path/to/your/data");
    

    Replace "path/to/your/data" with the actual path to your desired location.

    Write data to the database:

    Use the set method on the DatabaseReference to write data:

    myRef.set("Hello, World!");
    

    Read data from the database:

    Use the once method to get a snapshot of the data at a specific point in time:

    myRef.once().then((snapshot) {
      print(snapshot.value);
    });
    
    Login or Signup to reply.
  2. From the documentation of reference:

    @Deprecated('Deprecated in favor of calling ref().')
    DatabaseReference reference()
    Returns a DatabaseReference accessing the root of the database.

    So, use ref() instead of reference.

    This exact use-case is also covered in the documentation on getting a database reference.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search