Flutter How to get length of a iterable .toList() list?

343
Column(
         ...snapshot.data!.docs
             .asMap().map((index, value) => MapEntry(index, Card(
                    title: value["title"],)))
                 .values.toList(
                growable: true,
             ),
          ),
      
Share:
343
Cubii
Author by

Cubii

Updated on January 01, 2023

Comments

  • Cubii
    Cubii over 1 year

    I want to Display a ListView with Cards from FirebaseFirestore. Also, I want to show how many Cards there are at all:

    int Length = 0; //?
    

    How to get length of a iterable .toList() list?

         Column(
             children: snapshot.data!.docs
                 .map(
                    (doc) => 
                       Card(
                        title: doc["title"],)
                     .toList(
                    growable: true,
                 ),
              ),
           ),
    
    • Benyamin
      Benyamin over 2 years
      just add .length at the end of it: .toList().length;
    • Cubii
      Cubii over 2 years
      Error: The argument type 'int' can't be assigned to the parameter type 'List<Widget>'.
    • Benyamin
      Benyamin over 2 years
      Get the length before building the widget tree, and then use it in the tree.
  • novol
    novol over 2 years
    did it help you?
  • Cubii
    Cubii over 2 years
    can you tell me how I can set the State of the int Length for the number of the cards?
  • novol
    novol over 2 years
    why do you need it? Your widget will be built based on the length
  • Cubii
    Cubii over 2 years
    that's the point I want the length based on the generated length of the list? Or does this not work?
  • novol
    novol over 2 years
    this method include itemCount, if you want get length use snapshot.data!.docs.length