added analytics to RemoteConfigService

This commit is contained in:
Vadim 2024-01-27 20:59:10 +01:00
parent 683b506650
commit 147fedc36f
2 changed files with 10 additions and 8 deletions

View file

@ -26,11 +26,14 @@ class ApplicationWrapper extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final remoteConfigService = env.buildType != BuildType.dev
? const RemoteConfigService(LightmeterAnalytics(api: LightmeterAnalyticsFirebase()))
: const MockRemoteConfigService();
return FutureBuilder( return FutureBuilder(
future: Future.wait<dynamic>([ future: Future.wait<dynamic>([
SharedPreferences.getInstance(), SharedPreferences.getInstance(),
const LightSensorService(LocalPlatform()).hasSensor(), const LightSensorService(LocalPlatform()).hasSensor(),
if (env.buildType != BuildType.dev) const RemoteConfigService().activeAndFetchFeatures(), remoteConfigService.activeAndFetchFeatures(),
]), ]),
builder: (_, snapshot) { builder: (_, snapshot) {
if (snapshot.data != null) { if (snapshot.data != null) {
@ -47,8 +50,7 @@ class ApplicationWrapper extends StatelessWidget {
userPreferencesService: userPreferencesService, userPreferencesService: userPreferencesService,
volumeEventsService: const VolumeEventsService(LocalPlatform()), volumeEventsService: const VolumeEventsService(LocalPlatform()),
child: RemoteConfigProvider( child: RemoteConfigProvider(
remoteConfigService: remoteConfigService: remoteConfigService,
env.buildType != BuildType.dev ? const RemoteConfigService() : const MockRemoteConfigService(),
child: EquipmentProfileProvider( child: EquipmentProfileProvider(
storageService: iapService, storageService: iapService,
child: FilmsProvider( child: FilmsProvider(

View file

@ -2,9 +2,9 @@ import 'dart:async';
import 'dart:developer'; import 'dart:developer';
import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:firebase_remote_config/firebase_remote_config.dart'; import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:lightmeter/data/analytics/analytics.dart';
import 'package:lightmeter/data/models/feature.dart'; import 'package:lightmeter/data/models/feature.dart';
abstract class IRemoteConfigService { abstract class IRemoteConfigService {
@ -24,7 +24,9 @@ abstract class IRemoteConfigService {
} }
class RemoteConfigService implements IRemoteConfigService { class RemoteConfigService implements IRemoteConfigService {
const RemoteConfigService(); final LightmeterAnalytics analytics;
const RemoteConfigService(this.analytics);
@override @override
Future<void> activeAndFetchFeatures() async { Future<void> activeAndFetchFeatures() async {
@ -99,9 +101,7 @@ class RemoteConfigService implements IRemoteConfigService {
@override @override
bool isEnabled(Feature feature) => FirebaseRemoteConfig.instance.getBool(feature.name); bool isEnabled(Feature feature) => FirebaseRemoteConfig.instance.getBool(feature.name);
void _logError(dynamic throwable, {StackTrace? stackTrace}) { void _logError(dynamic throwable, {StackTrace? stackTrace}) => analytics.logCrash(throwable, stackTrace);
FirebaseCrashlytics.instance.recordError(throwable, stackTrace);
}
} }
class MockRemoteConfigService implements IRemoteConfigService { class MockRemoteConfigService implements IRemoteConfigService {