applySearch method

void applySearch(
  1. String query
)

Applies the search query to the device list and emits the new state.

Implementation

void applySearch(String query) {
  final keyword = query.trim().toLowerCase();
  final filtered =
      keyword.isEmpty
          ? state.allDevices
          : state.allDevices.where((device) {
            final name =
                (device.data['organizationName'] ?? '')
                    .toString()
                    .toLowerCase();
            return name.contains(keyword);
          }).toList();

  emit(state.copyWith(searchQuery: query, filteredDevices: filtered));
}