'A value of type 'DatabaseEvent' can't be assigned to a variable of type 'DataSnapshot' getting this error

The below code is giving this error (on the first line) when trying to retrieve data from database.

I am trying to edit contact details that I have saved to my database using the Map.


getContactDetail() async {
   DataSnapshot snapshot = await _ref.child(widget.clientKey).once() ;

    Map contact = snapshot.value as Map;

    _nameController.text = contact['name'];

    _numberController.text = contact['number'];

    _emailController.text = contact['email'];

    _addressController.text = contact['address'];

    _shopnameController.text = contact['shopname'];

    _gstController.text = contact['gst'];

    _areaController.text = contact['area'];
    
  }


Solution 1:[1]

once now returns a Future<DatabaseEvent>

Try:

DataSnapshot snapshot = (await _ref.child(widget.clientKey).once()).snapshot;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Josteve