setArchiveOnWithDatePicker static method
- BuildContext context,
- WidgetRef ref
Activate archive mode(appStateProvider.isArchive) only if allDaysWithServicesInited.dates not empty.
It also show date picker to set appStateProvider.atDate.
Implementation
static Future<void> setArchiveOnWithDatePicker(
BuildContext context,
WidgetRef ref,
) async {
await ref.read(allDaysWithServicesInited.future);
final archiveDates =
ref.read(allDaysWithServicesInited).asData?.value ?? <DateTime>{};
if (archiveDates.isEmpty) {
// ref.read(isArchiveProvider.notifier).state = false;
return;
}
if (context.mounted) {
final date = await showDatePicker(
context: context,
selectableDayPredicate: archiveDates.contains,
initialDate: archiveDates.last,
lastDate: archiveDates.last,
firstDate: archiveDates.first,
);
if (date != null) {
ref.watch(appStateProvider).toArchiveDate(date);
} else {
ref.watch(appStateProvider).toArchiveAll();
}
}
}