title: How can I find the number of objects in a list defined with a certain field? Flutter
body: <p>So I need to count the number of objects in the List that have a field with the value &quot;Category.walking&quot;. I tried iterating over with both &quot;for&quot; loop and &quot;forEach&quot;.</p>
  <pre><code>int countPets(){
  int count = 0;
    pets.forEach((element) {
      if (pets.contains(category.walking)){
        count++;
      }
    }
  );
    return count;
  </code></pre>
  <p>}</p>
  <p>But there is only one mistake - &quot;Undefined name 'category'.
  Try correcting the name to one that is defined, or defining the name.&quot; or The name 'Category' is defined in the libraries 'package:flutter/src/foundation/annotations.dart (via package:flutter/foundation.dart)' and 'package:petts/data.dart'.
  Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.</p>
  <p>This is how i made the data set in data.dart----</p>
  <pre><code>enum Category { walking, grooming, doctor, shop }
  enum Condition { park, cafe, training }
  
  class Pet {
    String name;
    String location;
    String distance;
    String condition;
    Category category;
    String imageUrl;
    bool favorite;
    bool newest;
  
    Pet(this.name, this.location, this.distance, this.condition, this.category,
        this.imageUrl, this.favorite, this.newest);
  }
  
  List&lt;Pet&gt; getPetList() {
    return &lt;Pet&gt;[
      Pet(
        &quot;&quot;,
        &quot;&quot;,
        &quot;&quot;,
        &quot;&quot;,
        Category.walking,
        &quot;&quot;,
        true,
        true,
      ),
      Pet(
        &quot;&quot;,
        &quot;&quot;,
        &quot;&quot;,
        &quot;&quot;,
        Category.walking,
        &quot;&quot;,
        false,
        false,
      ),
      Pet(
        &quot;&quot;,
        &quot;&quot;,
        &quot;&quot;,
        &quot;&quot;,
        Category.grooming,
        &quot;&quot;,
        true,
        true,
      ),
    ];
  }
  </code></pre>
  <p>And this in how i use this getPetList() in home_page.dart----</p>
  <pre><code>class HomePage extends StatefulWidget {
    const HomePage({Key? key}) : super(key: key);
  
    @override
    _HomePageState createState() =&gt; _HomePageState();
  }
  
  class _HomePageState extends State&lt;HomePage&gt; {
    List&lt;Pet&gt; pets = getPetList();
  
     ...there i need a counter...
  </code></pre>
  <p>Please, help me</p>