Hi everyone!
I am working on a custom action for FlutterFlow that will be used to set AppState and after filter a list view by date based on a userβs choice. The user can choose from three options: (Month), (Year), or (Week). Depending on the choice, I want to set the start date and end date accordingly. For example, if the user chooses Month, the start date should be the first day of the current month and the end date should be the current date. Similarly, if the user chooses Year, the start date should be the first day of the current year and the end date should be the current date. And if the user chooses week, the start date should be the first day of the current week and the end date should be the current date.
choice variable is the String based on choice chips options
I got my Listview filter set according to this logic, cheked action on choice chips added some extra actions like update appState and refresh Database Request - nothing seems to work The listView shows whole list no filtering
Any advice?
I have written the following code to implement this logic:
Future<void> filterListviewbydate(
String? choice,
DateTime? endDate,
DateTime? startDate,
) async {
// Validate parameters
if (choice != null && startDate != null && endDate != null) {
if (choice == "Month") {
DateTime now = DateTime.now();
startDate = DateTime(now.year, now.month, 1, 00, 00, 00);
endDate = DateTime.now();
} else if (choice == "Year") {
DateTime now = DateTime.now();
startDate = DateTime(now.year, 1, 1, 00, 00, 00);
endDate = DateTime.now();
} else if (choice == "Week") {
DateTime now = DateTime.now();
DateTime weekStart = now.subtract(Duration(days: now.weekday - 1));
startDate =
DateTime(weekStart.year, weekStart.month, weekStart.day, 00, 00, 00);
endDate = DateTime.now();
}
}
}
Future setState(DateTime startDate, DateTime endDate) async {
FFAppState().startDate = startDate;
FFAppState().endDate = endDate;