activateVoiceControlState static method

Future<bool> activateVoiceControlState({
  1. required String elementId,
  2. required String identifier,
})

Activates a state only on the currently presented voice template. CarPlay rate limits state changes. True means the host's active identifier matches the requested identifier immediately after activation.

Implementation

static Future<bool> activateVoiceControlState({
  required String elementId,
  required String identifier,
}) async {
  final template = FlutterCarPlayController.currentPresentTemplate;
  if (template is! CPVoiceControlTemplate ||
      template.uniqueId != elementId ||
      !template.voiceControlStates.any(
        (state) => state.identifier == identifier,
      )) {
    return false;
  }
  final completed = await FlutterCarPlayController.flutterToNativeModule(
    FCPChannelTypes.activateVoiceControlState,
    {'elementId': elementId, 'identifier': identifier},
    () =>
        identical(FlutterCarPlayController.currentPresentTemplate, template),
  );
  return completed == true &&
      identical(FlutterCarPlayController.currentPresentTemplate, template);
}