我在這個問題上發現的錯誤是什么 選擇沒有回應我 我不知道我錯了什么
這是我嘗試的第一種方式
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);
}
}
}
這是我嘗試的第二種方式
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);
}
});
它在第二個代碼中說

這是第一個代碼的問題

uj5u.com熱心網友回復:
ListCommunity 期望命名引數:
// Wrong:
ListCommunity(title, secondTitle, iconText, true, index)
// Good:
ListCommunity(title: title, secondTitle: secondTitle, iconText: iconText, isSelected: true, index: index)
閱讀有關 Dart 中命名引數的更多資訊:https : //dart.dev/guides/language/language-tour#parameters
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/352448.html
