title: Flutter - Multiselection ListView
body: <p>In my app, I do have a list, on which I have implemented the long press selection of <a href="https://stackoverflow.com/questions/49600048/flutter-listtile-enable-multi-select-onlongpress">this post of Raouf Rahiche</a>. When the selection is enabled I do have a different <code>appbar</code>, that has an <code>IconButton</code> on it, that should disable the selection. But I do not know how to do that. </p>
  
  <p>Till now it is not working the way it should. The behaviour is displayed in the video below.
  <a href="https://i.stack.imgur.com/Ib7OS.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/Ib7OS.gif" alt="enter image description here"></a></p>
  
  <p>The longpress-selection is a StatefulWidget:</p>
  
  <pre><code>class _SelectableItems extends State&lt;SelectableItems&gt; {
    bool isSelected = false;
    GoogleMaterialColors googleMaterialColors = new GoogleMaterialColors();
  
    @override
    void initState() {
      super.initState();
    }
  
    @override
    Widget build(BuildContext context) {
      return new GestureDetector(
          onLongPress: () {
            setState(() {
              isSelected = !isSelected;
            });
            widget.callback();
          },
          onTap: () {
            setState(() {
              isSelected = !isSelected;
            });
            if (widget.longPressEnabled) {
              widget.callback();
            } else {
              Navigator.push(
                context, 
                MaterialPageRoute(builder: (context)=&gt;RecipeDetails(widget.name))
              );
            }
          },
          child: ListTile(
            leading: CircleAvatar(
              child: (isSelected
                ? Icon(
                  Icons.check,
                  color: Colors.white,
                )
                : (widget.image != "no image"
                  ? Container(
                    width: 40.0,
                    height: 40.0,
                    decoration: new BoxDecoration(
                      image: new DecorationImage(
                        colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.2), BlendMode.darken),
                        image: AssetImage(widget.image),
                        fit: BoxFit.cover,
                      ),
                      borderRadius: new BorderRadius.all(new Radius.circular(50.0)),
                    ),
                  )
                  : Text(
                    widget.name[0].toUpperCase(),
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 21.0,
                      fontWeight: FontWeight.w400
                    ),
                  )
                )
              ),
              backgroundColor: (isSelected
                ? googleMaterialColors.primaryColor()
                : widget.color.withOpacity(1.00)
              )
            ),
            title: Padding(
              padding: EdgeInsets.only(top: 25.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: &lt;Widget&gt;[
                  widget.title
                ],
              ),
            ),
          ),
        );
    }
  }
  </code></pre>
  
  <p>I am calling this widget inside a <a href="https://pub.dartlang.org/packages/side_header_list_view" rel="noreferrer">SideHeaderListView</a> like this:</p>
  
  <pre><code>bool longPressFlag = false;
  List&lt;String&gt; indexList = new List();
  //other code
  
                  return SideHeaderListView(                  
                      hasSameHeader: (int a, int b){
                        return snapshot.data[a].name[0] == snapshot.data[b].name[0];                  
                      },
                      itemCount: snapshot.data.length,
                      headerBuilder: (BuildContext context, int index){
                        return new Padding(
                          padding: EdgeInsets.only(top: 30.0, left: 20.0, right: 25.0),
                          child: Container(
                            width: 10.0,
                            child: Text(
                              snapshot.data[index].name[0].toUpperCase(),
                              style: TextStyle(
                                color: googleMaterialColors.primaryColor().withGreen(120),                        
                                fontFamily: "Google-Sans",
                                fontSize: 15.0,
                                fontWeight: FontWeight.w600
                              ),
                            ),
                          ),
                        );
                      },
                      itemExtend: 70.0,
                      itemBuilder: (BuildContext context, int index){
  
                        Color usedColor = convertColor.convertToColor(snapshot.data[index].backgroundColor);                    
                        String image = snapshot.data[index].image;
  
  
                        return SelectableItems(
                          color: usedColor,
                          name: snapshot.data[index].name,
                          title: (searchController.text.isEmpty
                            ? Text(snapshot.data[index].name)
                            : recipeName(searchCondition, snapshot.data[index].name)
                          ),
                          index: index,
                          image: image,
                          longPressEnabled: longPressFlag,
                          //isSelected: selectedFlag,
                          callback: () {
                            if (indexList.contains(snapshot.data[index].name)) {
                              indexList.remove(snapshot.data[index].name);
                            } else {
                              indexList.add(snapshot.data[index].name);
                            }
                            longPress();
                          },
                        );
                      },
                    );
  
  void longPress() {
      setState(() {
        if (indexList.length == 0) {
          longPressFlag = false;
        } else {
          longPressFlag = true;
        }
      });
    }
  </code></pre>
  
  <p>I hope somebody would be able to solve my problem. Thanks in advance.</p>