KeyWordFlutterPC class

A class that manages a keyword detection engine and coordinates communication with native platforms using MethodChannel and EventChannel.

Each instance of KeyWordFlutterPC represents one keyword detection context identified by an instanceId. This class can:

  • Create a keyword detection instance with a given model.
  • Start/stop keyword detection.
  • Set the detection license.
  • Replace the detection model.
  • Start/stop a foreground service (Android).
  • Stream detection events to Flutter via onKeywordDetectionEvent.

Constructors

KeyWordFlutterPC(String instanceId, {bool isSticky = false})
Creates an instance of KeyWordFlutterPC with the given instanceId.

Properties

hashCode int
The hash code for this object.
no setterinherited
instanceId String
A string that uniquely identifies this detection instance.
final
isFirstInstance bool
This field indicates whether this instance is the first instance created. It is used to decide if a foreground service should be started.
getter/setter pair
isSticky bool
Whether to keep this detection service “sticky” on Android (i.e., run persistently as a foreground service). Defaults to false.
final
listeners List<StreamSubscription>
List of StreamSubscriptions listening to detection events. Useful for cleanup when the instance is destroyed.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createInstance(String modelName, double threshold, int bufferCnt) Future<bool>
Creates a new instance on the native side with the specified modelName, threshold, and bufferCnt.
destroyInstance() Future<void>
Destroys the native instance and frees any resources associated with it.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onKeywordDetectionEvent() Stream<String>
Returns a broadcast Stream of detected keyword phrases from the native platform. Each event represents a successful detection containing a phrase.
removeListeners() → void
Cancels all listeners currently active on this instance. This should be called prior to or as part of destroyInstance.
replaceKeywordDetectionModel(String modelName, double threshold, int bufferCnt) Future<bool>
Replaces the currently loaded keyword detection model with modelName, threshold, and bufferCnt.
setKeywordDetectionLicense(String license) Future<bool>
Sets the license string for keyword detection. Returns true if successful.
startForegroundService() Future<void>
Starts the Android foreground service for this instance, enabling continuous or “sticky” background detection. This call is ignored on iOS.
startKeywordDetection(String instanceId, double threshold) Future<bool>
Starts keyword detection for this instance using the specified instanceId and threshold.
stopForegroundService() Future<void>
Stops the Android foreground service for this instance. This call is ignored on iOS.
stopKeywordDetection() Future<bool>
Stops keyword detection for this instance. Returns true if successful.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited