RequestOptionsBuilder constructor

RequestOptionsBuilder(
  1. List<RequestFilterBuilder> requestFilters, {
  2. List<RequestFilterBuilder>? exclusionFilters,
  3. List<String>? optionalServices,
  4. List? optionalManufacturerData,
})

Tell the browser to only accept device matching the requestFilters. A device has to only match one filter, so if you support multiple device types then you add a filter for each device type.

A device may not have enough distinct information. To solve this you may add exclusionFilters. These are the same as the requestFilters, if a device matches ANY of these filters then it will not be available.

optionalServices is a list of services that are a nice to have. If a device doesn't have this service then the browser won't reject it.

optionalManufacturerData is a list of manufacturer codes. These codes are then used to grand access to specific manufacturer data. This can be a list of either strings in hexadecimal or ints. NOTE these values can be a maximum of unsigned 16 bits.

NOTE: You NEED to define a service in either the requestFilters or optionalServices if you want to be able to communicate with a characteristic in it.

NOTE: You NEED to define optionalManufacturerData if you want to get this manufacturer data later.

NOTE: exclusionFilters are only supported from Chrome 114 and above as well other browsers based on chromium.

May throw StateError if no filters are set, consider using RequestOptionsBuilder.acceptAllDevices.

Implementation

RequestOptionsBuilder(
  final List<RequestFilterBuilder> requestFilters, {
  final List<RequestFilterBuilder>? exclusionFilters,
  final List<String>? optionalServices,
  final List<dynamic>? optionalManufacturerData,
})  : _requestFilters = requestFilters,
      _acceptAllDevices = false,
      _exclusionFilters = exclusionFilters,
      _optionalServices = optionalServices,
      _optionalManufacturerData =
          RequestOptionsBuilder._convertOptionalManufacturerData(
              optionalManufacturerData) {
  if (_requestFilters.isEmpty) {
    throw StateError("No filters have been set, consider using "
        "RequestOptionsBuilder.acceptAllDevices() instead.");
  }
}