So i've tried it but with no success and would like to hear suggestions or solutions to this case I've added here all the relevant code from the page itself.
Widget build(BuildContext context) {
return FutureBuilder<ApiCallResponse>(
future: GetCandListByManagerCall.call(
entityId: widget.entityId,
),
builder: (context, snapshot) {
final listViewGetCandListByManagerResponse =
snapshot.data!;
final data = listViewGetCandListByManagerResponse.jsonBody['candList'] as List;
List<CandModel> cands = data.map((e) => CandModel.fromJson(e)).toList();
List<CandModel> filteredCands = cands;
DateTime now = new DateTime.now();
DateTime currentDate = new DateTime(now.year, now.month, now.day);
Expanded(
child: SwitchListTile.adaptive(
value: _value,
activeColor: Color(0xFF33CCCC),
onChanged: (bool value) {
setState(() {
_value = value;
if(_value = true)
{
checkWaitingEvents(); //Doesn't work lol
}
else
{//The idea is to add here a call to a function that will show only the Expired events in the listview}
});
},
selected: _value,
title: Text( 'Title',
textAlign: TextAlign.end,
style: FlutterFlowTheme.of(context).title3.override(
fontFamily: 'Outfit',
fontSize: 15,
),),
tileColor: FlutterFlowTheme.of(context).primaryBackground,
dense: false,
controlAffinity: ListTileControlAffinity.trailing,
contentPadding: EdgeInsetsDirectional.fromSTEB(0, 0, 80, 0),
),
),
return Builder(
builder: (context) {
if (data.isEmpty) {//The code of this part is Not Relevant as of right now }
return ListView.builder(
padding: EdgeInsets.zero,
scrollDirection: Axis.vertical,
itemCount: data.length,
itemBuilder: (context, dataIndex) {
List<CandModel> checkWaitingEvents()
{
DateTime expirationDate = DateTime.parse(cands[dataIndex].dateEvent);
if (expirationDate.isBefore(currentDate))
filteredCands.add(cands[dataIndex]);
//if correct then add the item to fliteredCands
return filteredCands;
}
final dataItem = data[dataIndex];
String date = (filteredCands[dataIndex].dateEvent).toString();
DateTime tempDate = DateTime.parse(date);
String exDate = DateFormat.yMMMd().format(tempDate);
return InkWell(
onTap: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
HistoryPageWidget(//Also not relevant),),);
},
child: SworkerContainerWidget(
desc: filteredCands[dataIndex].descEvent,
fname: filteredCands[dataIndex].wfirstName,
lname: filteredCands[dataIndex].wlastName,
dateEvent: exDate,
),
);
},
);
},
);
These are all the parts that are relevant on the page, I've tried filtering the list by dateEvent (if the value in switchTile is true, then the list will filter out all the events that have an expired date. if false then the list will show only the expired events) but seems like its way more difficult than I thought.