0

I have a Column that has two container

First Container has 3 chips [ 'All','Expenses','Income'], and second container having listview builder which shows data,

here I want to disable first container of chips while long press on list view's item, so that user can not tap on any chip..

in my following coding I have placed Container() to hide chip widgets..but here I want to show chips with disable mode...

Widget typeselection(){
    return islongpressed==true?Container():Container(
      child: Row(
        children: List<Widget>.generate(
          3,
              (int index) {
            return Row(children: [
              ChoiceChip(
                label: Container(
                  child: Text(_types[index]),
                  padding: EdgeInsets.symmetric(horizontal: 20),


                ),
                selected: _value == index,
                onSelected: (bool selected) {
                  setState(() {
                    _value = selected ? index : 0;
                  });
                },
                backgroundColor: Colors.blue.shade50,

                //padding: EdgeInsets.all(0),
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(10)),
                selectedColor: Colors.blue.shade100,
                padding: EdgeInsets.all(0),
              ),
              SizedBox(width: 10,),
            ],);
          },
        ).toList(),

      ),
    );


  }
Irfan Ganatra
  • 967
  • 3
  • 13

1 Answers1

1

If you want to block user from selecting chips when your condition is true you can try this:

Widget typeselection() {
    return Row(
      children: List<Widget>.generate(
        3,
        (int index) {
          return Row(
            children: [
              ChoiceChip(
                label: Container(
                  child: Text(_types[index]),
                  padding: EdgeInsets.symmetric(horizontal: 20),
                ),
                selected: _value == index,
                onSelected: (bool selected) {
                  if (islongpressed != true) {// <----- add this
                    setState(() {
                      _value = selected ? index : 0;
                    });
                  }
                },
                backgroundColor: Colors.blue.shade50,
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(10)),
                selectedColor: Colors.blue.shade100,
                padding: EdgeInsets.all(0),
              ),
              SizedBox(
                width: 10,
              ),
            ],
          );
        },
      ).toList(),
    );
  }
eamirho3ein
  • 16,619
  • 2
  • 12
  • 23