skip to Main Content

I have a Flutter app that was started and abandoned about four years ago. The project has resurfaced and I have been fixing the deprecated items that arose due to the updates made to Flutter in that time period. I have all but one area ready to begin testing, and that is reading from a Firebase Realtime Database into a List. The following is the code that has the error:

  return await dbReference
  .orderByChild(AppDatabase._speciesCommonName)
  .startAt(prefix)
  .endAt('$prefixuf8ff')
  .once()
  .then((DataSnapshot dataSnapshot) {
//
// Make sure we have data
//
if (dataSnapshot.value != null) {
  dataSnapshot.value.forEach((key, value) {
    String dbKey = key;
    String commonName = value[AppDatabase._speciesCommonName];
    Species obj = Species(dbKey: dbKey, commonName: commonName);
    list.add(obj);
  });

The error I get is:

The argument type ‘List Function(DataSnapshot)’ can’t be assigned to the parameter type ‘FutureOr<List> Function(DatabaseEvent)’.

I have searched and studied this code and the error, however, having been away from Flutter for those years I am failing to figure out the resolution.

A second error is also reported in the above code, however, I am hoping if the inital error is fixed so will this one:

The method ‘forEach’ isn’t defined for the type ‘Object’.

Any input would be greatly appreciated.

2

Answers


  1. in terminal

    flutter pub upgrade --major-verions
    

    then attempt to adapt the current code to the new update; occasionally, you will need to change the entirety of a package because some of them are discounted.

    Login or Signup to reply.
  2. Provide more code please.

    What’s the result being assigned to? When is it called?


    As for the forEach error, you have assumed that dataSnapshot.value will be a List but it’s not hence it isn’t working.

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