'How to get a combined list from realtime and firestore with flutter using realtime data as key?

I am trying to create a combined list from realtime and firestore, before the app starts, so that I can manipulate the data of this combined list, but I can't get the data. Can anyone help me?

my code:

Future<List<FinalGenerica>> generica() async {
  List<FinalGenerica> genFinal = [];
  final queryFirestore = firebaseFirestore.collection('designators');
  final queryReal =
      firebaseDatabase.ref('anagrafiche').orderByChild('store').equalTo("");

  List an = [];
  List de = [];

  return await queryReal.get().then((value) async {
    List<dynamic> res = value.value as dynamic;
    print(res);
    res.forEach((element) {
      if (element != null) {
        an.add(element);
      }
    });

    an.map((es) async {
      return  await queryFirestore
          .where('designatorNG', isEqualTo: es['designator'])
          .get()
          .then((QuerySnapshot snapshot) async {
        
        snapshot.docs.forEach((doc) {
          Map<String, dynamic> dy = doc.data() as Map<String, dynamic>;
          de.add(dy);
        });
        print(de);
        print(genFinal);
        de
            .map((j) async => {
                  genFinal.add(FinalGenerica(
                      cName: j['cName'],
                      cNumber: j['cNumber'],
                      accOwner: j['accOwner'],
                      data: es['data'],
                      pmfData: es['pmfData']))
                })
            .toList();

        return genFinal;
      });
    }).toList();

    return genFinal;
  });
}

The code should return the combined list, like a Future<List <FinalGenerica>> used in my bloc provider, and bloc builder. But apparently it gets nothing and doesn't even report the error. However when I try to do a print ( final list) I print:

Instance of 'Final list'

I can see my list from realtime, and also the one from firestore, but I can't get the final combined list.

Where am i wrong?

enter image description here



Sources

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

Source: Stack Overflow

Solution Source