In my onChanged method, I add an entry to the list and change the state of the checkbox. How to move onChanged into a separate method?
BlocConsumer<StudentBloc, StudentState>(
listener: _checkboxListener,
builder: (context, state) {
return Expanded(
child: ListView.builder(
itemCount: _lessonsList.length,
itemBuilder: (BuildContext context, int index) {
final lesson = _lessonsList[index];
bool? checkboxValue = _checkboxValues[index];
return CheckboxListTile(
title: Text(lesson.lessonName ?? ''),
controlAffinity: ListTileControlAffinity.leading,
contentPadding: EdgeInsets.zero,
value: checkboxValue,
onChanged: (bool? value) {
_checkedLesson.add(lesson);
setState(
() {
_checkboxValues[index] = value ?? false;
},
);
},
);
},
),
);
},
),