37 lines
1.1 KiB
Dart
37 lines
1.1 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../models/attendance.dart';
|
|
import '../repositories/attendance_repository.dart';
|
|
import 'auth_provider.dart';
|
|
|
|
final attendanceRepositoryProvider = Provider<AttendanceRepository>((ref) {
|
|
final apiClient = ref.watch(apiClientProvider);
|
|
return AttendanceRepository(apiClient: apiClient);
|
|
});
|
|
|
|
class AttendanceFilter {
|
|
final String? fromDate;
|
|
final String? toDate;
|
|
|
|
const AttendanceFilter({this.fromDate, this.toDate});
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is AttendanceFilter &&
|
|
runtimeType == other.runtimeType &&
|
|
fromDate == other.fromDate &&
|
|
toDate == other.toDate;
|
|
|
|
@override
|
|
int get hashCode => fromDate.hashCode ^ toDate.hashCode;
|
|
}
|
|
|
|
final attendanceProvider = FutureProvider.autoDispose
|
|
.family<AttendanceData, AttendanceFilter>((ref, filter) async {
|
|
final repository = ref.watch(attendanceRepositoryProvider);
|
|
return await repository.getAttendance(
|
|
fromDate: filter.fromDate,
|
|
toDate: filter.toDate,
|
|
);
|
|
});
|