setRootTemplate static method

void setRootTemplate({
  1. required dynamic rootTemplate,
  2. bool animated = true,
})

Sets the root template of the navigation hierarchy. If a navigation hierarchy already exists, CarPlay replaces the entire hierarchy.

  • rootTemplate is a template to use as the root of a new navigation hierarchy. If one exists, it will replace the current rootTemplate. Must be one of the type: CPTabBarTemplate, CPGridTemplate, CPListTemplate If not, it will throw an TypeError

  • If animated is true, CarPlay animates the presentation of the template, but will be ignored this flag when there isn’t an existing navigation hierarchy to replace.

! CarPlay cannot have more than 5 templates on one screen.

Implementation

static void setRootTemplate({
  required dynamic rootTemplate,
  bool animated = true,
}) {
  if (rootTemplate.runtimeType == CPTabBarTemplate ||
      rootTemplate.runtimeType == CPGridTemplate ||
      rootTemplate.runtimeType == CPListTemplate ||
      rootTemplate.runtimeType == CPInformationTemplate ||
      rootTemplate.runtimeType == CPPointOfInterestTemplate) {
    _carPlayController.methodChannel
        .invokeMethod('setRootTemplate', <String, dynamic>{
      'rootTemplate': rootTemplate.toJson(),
      'animated': animated,
      'runtimeType': "F" + rootTemplate.runtimeType.toString(),
    }).then((value) {
      if (value) {
        FlutterCarPlayController.currentRootTemplate = rootTemplate;
        _carPlayController.addTemplateToHistory(rootTemplate);
      }
    });
  }
}