2

I used this code bevor migration

  void initState() {
    DatabaseReference db;
    db = FirebaseDatabase.instance.ref().child("likes");
    db.once().then((DataSnapshot snapshot) {
      Map<dynamic, dynamic> values = snapshot.value;
      values.forEach((key, values) {
        likeList.add(values["check"]);
        print(likeList);
      });
    });
  }

after "dart pub upgrade --null-safety" I get the Error:

The argument type 'Null Function(DataSnapshot)' can't be assigned to the parameter type 'FutureOr<dynamic> Function(DatabaseEvent)

I can't find anything in the changelos on pub.dev how to use DataSnapshot in this case.

Bernhard
  • 188
  • 10
  • https://stackoverflow.com/questions/70585172/the-argumnet-type-null-funciondatasnapshot-cnt-be-assigned-to-the-parameter – Anmol Mishra Feb 08 '22 at 04:32

1 Answers1

1

Instead of DataSnapshot, you should put DatabaseEvent within the then

  void initState() {
    DatabaseReference db;
    db = FirebaseDatabase.instance.ref().child("likes");
    db.once().then((DatabaseEvent databaseEvent) {
      Map<dynamic, dynamic> values = databaseEvent.snapshot.value;
      values.forEach((key, values) {
        likeList.add(values["check"]);
        print(likeList);
      });
    });
  }
Sahil Hariyani
  • 1,078
  • 3
  • 11