title: Single Selection for ListView Flutter
body: <p>I am trying to implement a <code>listView</code> single selection in my app such that once an item in the list is tapped such that pressed item color state is different from the others. I have done all I know but it does not work well. The problem is that even though my implementation updates each item state when pressed, it doesn't reset the others to their initial state.</p>
  <p><a href="https://i.stack.imgur.com/6c761m.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6c761m.png" alt="expected output" /></a></p>
  <pre><code>class BoxSelection{
    bool isSelected;
    String title;
    String options;
    BoxSelection({this.title, this.isSelected, this.options});
  }
  
  
  class _AddProjectState extends State&lt;AddProject&gt; {
    List&lt;BoxSelection&gt; projectType = new List();
    @override
    void didChangeDependencies() {
      super.didChangeDependencies();
      projectType
          .add(BoxSelection(title: &quot;Building&quot;, isSelected: false, options: &quot;A&quot;));
      projectType
          .add(BoxSelection(title: &quot;Gym House&quot;, isSelected: false, options: &quot;B&quot;));
      projectType
          .add(BoxSelection(title: &quot;School&quot;, isSelected: false, options: &quot;C&quot;));
    }
  
    child: ListView.builder(
                        itemCount: projectType.length,
                        itemBuilder: (BuildContext context, int index) {
                          return GestureDetector(
                            onTap: () {
                              setState(() {
         //here am trying to implement single selection for the options in the list but it don't work well
                                for(int i = 0; i &lt; projectType.length; i++) {
                                  if (i == index) {
                                    setState(() {
                                      projectType[index].isSelected = true;
                                    });
                                  } else {
                                    setState(() {
                                      projectType[index].isSelected = false;
                                    });
                                  }
                                }
                              });
                            },
                            child: BoxSelectionButton(
                              isSelected: projectType[index].isSelected,
                              option: projectType[index].options,
                              title: projectType[index].title,
                            ),
                          );
                        },
                      ),
  </code></pre>