fetchDeviceData method

Future<void> fetchDeviceData()

Fetches device data from Appwrite and updates the state.

Applies the current date filters and search query.

Implementation

Future<void> fetchDeviceData() async {
  emit(state.copyWith(isLoading: true));
  try {
    final devices = await fetchDevices(
      _db,
      fromDate: state.fromDate,
      tillDate: state.tillDate,
    );
    emit(
      state.copyWith(
        allDevices: devices,
        filteredDevices: devices,
        isLoading: false,
      ),
    );
    applySearch(state.searchQuery); // Apply search after fetch
  } catch (e) {
    emit(state.copyWith(isLoading: false, errorMessage: e.toString()));
  }
}