title: Flutter: All ListTile Items responding same click
body: <p>I am new to flutter so I was trying to build a scrollable listtile objects. So after building it I tried to make the iconbutton change color when onpressed which works but when I press a single button it changes the colors of all the items. I guess it has to do with assigning a unique id/key to each of the items but am not sure if thats the issue or even how to do that. The code is below:</p>
  <pre class="lang-dart prettyprint-override"><code>class Lists extends StatefulWidget {
    @override
    _ListsState createState() =&gt; _ListsState();
  }
  
  class _ListsState extends State&lt;Lists&gt; {
    Color _statusColor = Colors.grey;
  
    List&lt;ItemLists&gt; items = [
      ItemLists(
        title: 'Best Music of the Year',
        discription: 'Davido',
      ),
      ItemLists(
        title: 'Best Album Cover design',
        discription: 'Brighter Press',
      ),
      ItemLists(
        title: 'Best Vocalist',
        discription: 'Simi-Sola',
      ),
    ];
    @override
    Widget build(BuildContext context) {
      return Column(
          children: items.map(
                (items) {
              return Container(
                  child: Card(
                      child: ListTile(
                        leading: new IconButton(
                            icon: Icon(
                              Icons.star,
                              color: _statusColor,
                            ),
                            tooltip: 'Add to Favorite',
                            onPressed: () {
                              setState(() {
                                if (_statusColor == Colors.grey) {
                                  _statusColor = Colors.green;
                                } else {
                                  _statusColor = Colors.grey;
                                }
                              });
                            }),
                        title: Text('${items.title}'),
                        subtitle: Text('${items.discription}'),
                        trailing: IconButton(icon: Icon(Icons.delete), onPressed: null),
                      )));
            },
          ).toList());
    }
  }
  </code></pre>
  <p>Thanks in advance.</p>
  <p>Below is the edited code</p>
  <pre class="lang-dart prettyprint-override"><code>class Lists extends StatefulWidget {
    @override
    _ListsState createState() =&gt; _ListsState();
  }
  
  class _ListsState extends State&lt;Lists&gt; {
    Color _statusColor = Colors.grey;
  
    List&lt;ItemLists&gt; items = [
      ItemLists(
        title: 'Best Music of the Year',
        discription: 'Davido',
        favorite: false,
      ),
      ItemLists(
        title: 'Best Album Cover design',
        discription: 'Brighter Press',
        favorite: false,
      ),
      ItemLists(
        title: 'Best Vocalist',
        discription: 'Simi-Sola',
        favorite: false,
      ),
    ];
    @override
    Widget build(BuildContext context) {
      return Column(
          children: items.map(
                (items) {
              return Container(
                  child: Card(
                      child: ListTile(
                        leading: new IconButton(
                            icon: Icon(
                              Icons.star,
                              color: items.favorite ? Colors.green : Colors.grey,
                            ),
                            tooltip: 'Add to Favorite',
                            onPressed: () {
                              setState(() {
                                items.favorite = !items.favorite;
                              });
                            }),
                        title: Text('${items.title}'),
                        subtitle: Text('${items.discription}'),
                        trailing: IconButton(icon: Icon(Icons.delete), onPressed: null),
                      )));
            },
          ).toList());
    }
  }
  </code></pre>
  <p>Then below is my data model</p>
  <pre class="lang-dart prettyprint-override"><code>class ItemLists {
    String title;
    String discription;
    bool favorite;
  
    ItemLists({this.title, this.discription, this.favorite});
  }
  </code></pre>
  <p>What am trying to do is a Todo app where the user can easily click the star iconbutton when he or she is done with a particular task.</p>