From e9041b76cde1b3d709999b70014541e57c0f1a0e Mon Sep 17 00:00:00 2001 From: Koen Van Looveren Date: Mon, 19 Sep 2022 15:59:01 +0200 Subject: [PATCH 1/2] Match dart casing --- ios/Classes/FCPEnums.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/Classes/FCPEnums.swift b/ios/Classes/FCPEnums.swift index 613afec..71cef70 100644 --- a/ios/Classes/FCPEnums.swift +++ b/ios/Classes/FCPEnums.swift @@ -6,9 +6,9 @@ // enum FCPConnectionTypes { - static let connected = "CONNECTED" - static let background = "BACKGROUND" - static let disconnected = "DISCONNECTED" + static let connected = "connected" + static let background = "background" + static let disconnected = "disconnected" } enum FCPChannelTypes { From eb228d818d64533c4fc2dc284ea58a2004843520 Mon Sep 17 00:00:00 2001 From: Koen Van Looveren Date: Mon, 19 Sep 2022 16:15:12 +0200 Subject: [PATCH 2/2] Removed runtimeType toStrings --- lib/carplay_worker.dart | 20 ++++++++++++++++++-- lib/controllers/carplay_controller.dart | 18 +++++++++--------- lib/helpers/carplay_helper.dart | 4 ++-- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/lib/carplay_worker.dart b/lib/carplay_worker.dart index 001be23..1ec0591 100644 --- a/lib/carplay_worker.dart +++ b/lib/carplay_worker.dart @@ -137,7 +137,7 @@ class FlutterCarplay { _carPlayController.methodChannel.invokeMethod('setRootTemplate', { 'rootTemplate': rootTemplate.toJson(), 'animated': animated, - 'runtimeType': "F" + rootTemplate.runtimeType.toString(), + 'runtimeType': "F" + _getTemplateType(rootTemplate), }).then((value) { if (value) { FlutterCarPlayController.currentRootTemplate = rootTemplate; @@ -251,7 +251,7 @@ class FlutterCarplay { bool isCompleted = await _carPlayController.reactToNativeModule(FCPChannelTypes.pushTemplate, { "template": template.toJson(), "animated": animated, - "runtimeType": "F" + template.runtimeType.toString(), + "runtimeType": "F" + _getTemplateType(template), }); if (isCompleted) { _carPlayController.addTemplateToHistory(template); @@ -262,6 +262,22 @@ class FlutterCarplay { } } + static String _getTemplateType(dynamic template) { + if (template is CPTabBarTemplate) { + return 'CPTabBarTemplate'; + } else if (template is CPGridTemplate) { + return 'CPGridTemplate'; + } else if (template is CPInformationTemplate) { + return 'CPInformationTemplate'; + } else if (template is CPPointOfInterestTemplate) { + return 'CPPointOfInterestTemplate'; + } else if (template is CPListTemplate) { + return 'CPListTemplate'; + } else { + throw TypeError(); + } + } + /// Navigate to the shared instance of the NowPlaying Template /// /// - If animated is true, CarPlay animates the transition between templates. diff --git a/lib/controllers/carplay_controller.dart b/lib/controllers/carplay_controller.dart index a5c2f6a..da28bfe 100644 --- a/lib/controllers/carplay_controller.dart +++ b/lib/controllers/carplay_controller.dart @@ -78,11 +78,11 @@ class FlutterCarPlayController { } void addTemplateToHistory(dynamic template) { - if (template.runtimeType == CPTabBarTemplate || - template.runtimeType == CPGridTemplate || - template.runtimeType == CPInformationTemplate || - template.runtimeType == CPPointOfInterestTemplate || - template.runtimeType == CPListTemplate) { + if (template is CPTabBarTemplate || + template is CPGridTemplate || + template is CPInformationTemplate || + template is CPPointOfInterestTemplate || + template is CPListTemplate) { templateHistory.add(template); } else { throw TypeError(); @@ -120,7 +120,7 @@ class FlutterCarPlayController { CPGridButton? gridButton; l1: for (var t in templateHistory) { - if (t.runtimeType.toString() == "CPGridTemplate") { + if (t is CPGridTemplate) { for (var b in t.buttons) { if (b.uniqueId == elementId) { gridButton = b; @@ -136,7 +136,7 @@ class FlutterCarPlayController { CPBarButton? barButton; l1: for (var t in templateHistory) { - if (t.runtimeType.toString() == "CPListTemplate") { + if (t is CPListTemplate) { barButton = t.backButton; break l1; } @@ -147,7 +147,7 @@ class FlutterCarPlayController { void processFCPTextButtonPressed(String elementId) { l1: for (var t in templateHistory) { - if (t.runtimeType.toString() == "CPPointOfInterestTemplate") { + if (t is CPPointOfInterestTemplate) { for (CPPointOfInterest p in t.poi) { if (p.primaryButton != null && p.primaryButton!.uniqueId == elementId) { p.primaryButton!.onPress(); @@ -159,7 +159,7 @@ class FlutterCarPlayController { } } } else { - if (t.runtimeType.toString() == "CPInformationTemplate") { + if (t is CPInformationTemplate) { l2: for (CPTextButton b in t.actions) { if (b.uniqueId == elementId) { diff --git a/lib/helpers/carplay_helper.dart b/lib/helpers/carplay_helper.dart index b28f601..f86fa39 100644 --- a/lib/helpers/carplay_helper.dart +++ b/lib/helpers/carplay_helper.dart @@ -9,11 +9,11 @@ class FlutterCarplayHelper { l1: for (var t in templates) { List listTemplates = []; - if (t.runtimeType.toString() == (CPTabBarTemplate).toString()) { + if (t is CPTabBarTemplate) { for (var template in t.templates) { listTemplates.add(template); } - } else if (t.runtimeType.toString() == (CPListTemplate).toString()) { + } else if (t is CPListTemplate) { listTemplates.add(t); } if (listTemplates.isNotEmpty) {