capabilityChanged method

Stream<CapabilityInfo> capabilityChanged({
  1. String? capabilityName,
  2. Uri? capabilityPathURI,
  3. UriFilterType filterType = UriFilterType.literal,
})

Listen to a capability changed

You can listen to a specific capability via name/path or a group of capability via path

This Stream emit a CapabilityInfo each time the capability's changed.

Implementation

Stream<CapabilityInfo> capabilityChanged(
    {String? capabilityName,
    Uri? capabilityPathURI,
    UriFilterType filterType = UriFilterType.literal}) async* {
  if (capabilityName == null && capabilityPathURI == null) {
    throw "Name or uri must be specified";
  }
  await removeCapabilityListener(
      capabilityName: capabilityName, capabilityPathURI: capabilityPathURI);
  await channel.invokeMethod(
      "addCapabilityListener",
      capabilityName != null
          ? {
              "name": capabilityName,
            }
          : {
              "path": capabilityPathURI.toString(),
              "filterType": filterType.index
            });

  String key = capabilityName ?? capabilityPathURI.toString();
  Map<String, StreamController<CapabilityInfo>>
      _capabilityInfoStreamControllers =
      _wearOSObserver.streamControllers[ObservableType.capability]
          as Map<String, StreamController<CapabilityInfo>>;
  _capabilityInfoStreamControllers[key] = StreamController.broadcast();
  yield* _capabilityInfoStreamControllers[key]!.stream;
}