Home > Software design >  Flutter The getter 'documents' isn't defined for the type 'QuerySnapshot<Obje
Flutter The getter 'documents' isn't defined for the type 'QuerySnapshot<Obje

Time:09-20

I am getting this error in my flutter app:

The getter 'documents' isn't defined for the type 'QuerySnapshot'. Try importing the library that defines 'documents', correcting the name to the name of an existing getter, or defining a getter or field named 'documents'.

Here is my code:


  getExpenseItems(AsyncSnapshot<QuerySnapshot> snapshot) {
    List<ElementTask> listElement = new List(), listElement2;
    Map<String, List<ElementTask>> userMap = new Map();

    List<String> cardColor = new List();
    if (widget.user.uid.isNotEmpty) {
      cardColor.clear();

      snapshot.data.documents.map<List>((f) {
        f.data.forEach((a, b) {
          if (b.runtimeType == bool) {
            listElement.add(new ElementTask(a, b));
          }
          if (b.runtimeType == String && a == "color") {
            cardColor.add(b);
          }
        });
        listElement2 = new List<ElementTask>.from(listElement);
        userMap[f.documentID] = listElement2;

        for (int i = 0; i < listElement2.length; i  ) {
          if (listElement2.elementAt(i).isDone == false) {
            userMap.remove(f.documentID);
            if (cardColor.isNotEmpty) {
              cardColor.removeLast();
            }

            break;
          }
        }
        if (listElement2.length == 0) {
          userMap.remove(f.documentID);
          cardColor.removeLast();
        }
        listElement.clear();
      }).toList();

      return new List.generate(userMap.length, (int index) {
        return new GestureDetector(
          onTap: () {
            Navigator.of(context).push(
              new PageRouteBuilder(
                pageBuilder: (_, __, ___) => new DetailPage(
                      user: widget.user,
                      i: index,
                      currentList: userMap,
                      color: cardColor.elementAt(index),
                    ),
                transitionsBuilder:
                    (context, animation, secondaryAnimation, child) =>
                        new ScaleTransition(
                          scale: new Tween<double>(
                            begin: 1.5,
                            end: 1.0,
                          ).animate(
                            CurvedAnimation(
                              parent: animation,
                              curve: Interval(
                                0.50,
                                1.00,
                                curve: Curves.linear,
                              ),
                            ),
                          ),
                          child: ScaleTransition(
                            scale: Tween<double>(
                              begin: 0.0,
                              end: 1.0,
                            ).animate(
                              CurvedAnimation(
                                parent: animation,
                                curve: Interval(
                                  0.00,
                                  0.50,
                                  curve: Curves.linear,
                                ),
                              ),
                            ),
                            child: child,
                          ),
                        ),
              ),
            );
          },

enter image description here

Does anyone know how I can solve this issue?

CodePudding user response:

documents are now replaced with 
QuerySnapshot documents=snapshot.data.docs

CodePudding user response:

I have tried this code but it gives me error on last row:

The method 'toList' isn't defined for the type 'Function'. Try correcting the name to the name of an existing method, or defining a method named 'toList'.

getxpenseItems(AsyncSnapshot<QuerySnapshot> snapshot) {
List<ElementTask> listElement = new List(), listElement2;
Map<String, List<ElementTask>> userMap = new Map();

List<String> cardColor = new List();
if (widget.user.uid.isNotEmpty) {
  cardColor.clear();

  snapshot.data.docs.forEach(((f) {
    f.data.forEach((a, b) {
      if (b.runtimeType == bool) {
        listElement.add(new ElementTask(a, b));
      }
      if (b.runtimeType == String && a == "color") {
        cardColor.add(b);
      }
    });
    listElement2 = new List<ElementTask>.from(listElement);
    userMap[f.documentID] = listElement2;

    for (int i = 0; i < listElement2.length; i  ) {
      if (listElement2.elementAt(i).isDone == false) {
        userMap.remove(f.documentID);
        if (cardColor.isNotEmpty) {
          cardColor.removeLast();
        }

        break;
      }
    }
    if (listElement2.length == 0) {
      userMap.remove(f.documentID);
      cardColor.removeLast();
    }
    listElement.clear();
  }).toList());
  • Related