Home > Back-end >  Multi Selection ListView is not response
Multi Selection ListView is not response

Time:11-08

What's the mistake that i found on this problem the selection not response me i don't know what i was mistake

this is the 1st way i was try

onTap: () {
          selectCommunity(ListCommunity _communityList) {
            if (widget.isMultiSelection) {
              final isSelected = selectedCommunityList.contains(_communityList);
              setState(() => isSelected
                  ? selectedCommunityList.remove(_communityList)
                  : selectedCommunityList.add(_communityList));
            } else {
              Navigator.pop(context, _communityList);
            }
          }
        }

this is the 2nd way i was try

setState(() {
            _communityList[index].isSelected =
                !_communityList[index].isSelected;
            if (_communityList[index].isSelected == true) {
              selectedCommunityList.add(
                  ListCommunity(title, secondTitle, iconText, true, index));
            } else if (_communityList[index].isSelected == false) {
              selectedCommunityList.removeWhere(
                  (element) => element.title == _communityList[index].title);
            }
          });

it's said on 2nd code enter image description here

it's problem on 1st code enter image description here

CodePudding user response:

ListCommunity expects named parameters:

// Wrong:
ListCommunity(title, secondTitle, iconText, true, index)

// Good:
ListCommunity(title: title, secondTitle: secondTitle, iconText: iconText, isSelected: true, index: index)

Read more about named parameters in Dart: https://dart.dev/guides/language/language-tour#parameters

  • Related