setRootTemplate static method

Future<void> setRootTemplate({
  1. required CPTemplate rootTemplate,
  2. bool animated = true,
})

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

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

Implementation

static Future<void> setRootTemplate({
  required CPTemplate rootTemplate,
  bool animated = true,
}) async {
  if (rootTemplate is CPTabBarTemplate ||
      rootTemplate is CPGridTemplate ||
      rootTemplate is CPListTemplate ||
      rootTemplate is CPInformationTemplate ||
      rootTemplate is CPPointOfInterestTemplate ||
      rootTemplate is CPSearchTemplate) {
    return FlutterCarPlayController.flutterToNativeModule(
        FCPChannelTypes.setRootTemplate, <String, dynamic>{
      'rootTemplate': rootTemplate.toJson(),
      'animated': animated,
    }).then((value) {
      if (value == true) {
        if (FlutterCarPlayController.templateHistory.isEmpty) {
          FlutterCarPlayController.templateHistory.add(rootTemplate);
        } else {
          FlutterCarPlayController.templateHistory[0] = rootTemplate;
        }
      }
    });
  } else {
    throw TypeError();
  }
}