diff --git a/lib/application_wrapper.dart b/lib/application_wrapper.dart index e2c6136..4e95f40 100644 --- a/lib/application_wrapper.dart +++ b/lib/application_wrapper.dart @@ -33,9 +33,9 @@ class ApplicationWrapper extends StatefulWidget { } class _ApplicationWrapperState extends State { - late final remoteConfigService = widget.env.buildType != BuildType.dev - ? const RemoteConfigService(LightmeterAnalytics(api: LightmeterAnalyticsFirebase())) - : const MockRemoteConfigService(); + static const analytics = LightmeterAnalytics(api: LightmeterAnalyticsFirebase()); + late final remoteConfigService = + widget.env.buildType != BuildType.dev ? const RemoteConfigService(analytics) : const MockRemoteConfigService(); late final UserPreferencesService userPreferencesService; late final bool hasLightSensor; @@ -100,7 +100,7 @@ class _ApplicationWrapperState extends State { await Future.wait([ SharedPreferences.getInstance(), const LightSensorService(LocalPlatform()).hasSensor(), - const CameraInfoService().mainCameraEfl(), + const CameraInfoService(analytics).mainCameraEfl(), remoteConfigService.activeAndFetchFeatures(), equipmentProfilesStorageService.init(), filmsStorageService.init(), diff --git a/lib/data/camera_info_service.dart b/lib/data/camera_info_service.dart index 44819b6..82612b0 100644 --- a/lib/data/camera_info_service.dart +++ b/lib/data/camera_info_service.dart @@ -1,5 +1,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; +import 'package:lightmeter/data/analytics/analytics.dart'; class CameraInfoService { @visibleForTesting @@ -7,10 +8,26 @@ class CameraInfoService { "com.vodemn.lightmeter.CameraInfoPlatformChannel.MethodChannel", ); - const CameraInfoService(); + final LightmeterAnalytics analytics; + + const CameraInfoService(this.analytics); Future mainCameraEfl() async { - final focalLength = await cameraInfoPlatformChannel.invokeMethod('mainCameraEfl'); - return focalLength?.round(); + try { + final focalLength = await cameraInfoPlatformChannel.invokeMethod('mainCameraEfl'); + return focalLength?.round(); + } on PlatformException catch (e) { + analytics.logEvent( + e.code, + parameters: { + "message": "${e.message}", + "details": e.details.toString(), + }, + ); + return null; + } catch (e) { + analytics.logEvent(e.toString()); + return null; + } } }