listview.builder
항목을 탭하면 다른 항목이 선택 취소되고 마지막 탭만 선택되도록 내 단일 선택을 구현하려고합니다 . 이것은 내 논리이지만 지금은 다중 선택을 수행하며 단일로 만드는 방법에 갇혀 있습니다.
FlatButton(
onPressed: () {
setState(() {
_bloc.similarProducts[index].selected =
!_bloc.similarProducts[index].selected;
});
},
child: Container(
height: 45,
width:120,
decoration: BoxDecoration(
border: Border.all(
color:!_bloc.similarProducts
[index].selected?
Colors.white:
Hexcolor("#DADE66"),
),
borderRadius: BorderRadius.circular(7),
color: !_bloc.similarProducts[index].selected?
Hexcolor("#DADE66"):
Colors.white,
),
padding: EdgeInsets.all(12),
child: Padding(
padding: const EdgeInsets.only(left:15.0, right:15.0),
child: Center(
child: Text(
!_bloc.similarProducts[index].selected?
"Select": "Selected",
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 14,
fontFamily: 'Lato',
color: !_bloc.similarProducts
[index].selected?
Colors.white:
Hexcolor("#DADE66"),
),
),
),
),
),
),
],
);
}
),
하나의 항목 만 선택하려면 새 값을 만들 수 있으므로 selectedItem이라고합니다. 그런 다음 FlatButton onPressed 콜백에서 selectedItem을 선택하려는 항목의 값으로 설정합니다 (값은 색인, ID 또는 고유 식별자 일 수 있으며 자체 항목 일 수 있음).
그런 다음 원하는 항목을 표시하는 것과 같으면 목록의 모든 항목에서 값을 확인할 수 있습니다.
이렇게하면 새 항목을 선택할 때 이전 항목이 대체되므로 하나만 선택됩니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다