Filter Listview by choice chip date range

Actions & Logic

Hi there,

I'm currently facing a challenge with implementing a custom action. My goal is to filter a listview of events by date. To achieve this, I've set up choice chips labeled 'This Week,' 'Next Week,' and 'This Month.' By selecting one of these options, the listview should dynamically filter all events according to my choice.

Further, when I click on choice chip "date", a calendar widget pops up and I can filter the events by a specific date:

This is my custom action:

// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

Future<DateTime> filterListviewbyDate(String? choice) async {
  // Filter listview on choice this week, next week and this month by startdate of event
// Assuming that the listview data is stored in a list of events with a start date property

  DateTime now = DateTime.now();
  DateTime startDate;

  switch (choice) {
    case "This Week":
      startDate = now.subtract(Duration(days: now.weekday - 1));
      break;
    case "Next Week":
      startDate = now.add(Duration(days: 7 - now.weekday + 1));
      break;
    case "This Month":
      startDate = DateTime(now.year, now.month, 1);
      break;
    default:
      startDate = now;
      break;
  }

  return startDate;
}

And here are my action settings:

So I'm providing the selected choice chip as a string. Further I set an action on the choice chips:

I also set an Appstate "setStartDate" with the current time and after that I set the custom action. Somehow my listview won't filter the events like I want :D.

Could someone please review this and provide guidance on where I might be making a mistake?

Thanks in advance!! Marvin

What have you tried so far?
  • tried a custom action via code copilot

  • checked the community posts (there is a similiar post from vladimir "Filter ListView with DateRange from choice chips. Help needed" but I couldn't fit it to my need)

  • checked the documentation

Did you check FlutterFlow's Documentation for this topic?
Yes
2
6 replies