mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 23:40:41 +00:00
implemented RemoteConfigService
This commit is contained in:
parent
f3b08868be
commit
e83e6cff3a
6 changed files with 86 additions and 12 deletions
|
@ -3,11 +3,13 @@ import 'package:lightmeter/data/caffeine_service.dart';
|
||||||
import 'package:lightmeter/data/haptics_service.dart';
|
import 'package:lightmeter/data/haptics_service.dart';
|
||||||
import 'package:lightmeter/data/light_sensor_service.dart';
|
import 'package:lightmeter/data/light_sensor_service.dart';
|
||||||
import 'package:lightmeter/data/permissions_service.dart';
|
import 'package:lightmeter/data/permissions_service.dart';
|
||||||
|
import 'package:lightmeter/data/remote_config_service.dart';
|
||||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||||
import 'package:lightmeter/data/volume_events_service.dart';
|
import 'package:lightmeter/data/volume_events_service.dart';
|
||||||
import 'package:lightmeter/environment.dart';
|
import 'package:lightmeter/environment.dart';
|
||||||
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
||||||
import 'package:lightmeter/providers/films_provider.dart';
|
import 'package:lightmeter/providers/films_provider.dart';
|
||||||
|
import 'package:lightmeter/providers/remote_config_provider.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.dart';
|
import 'package:lightmeter/providers/services_provider.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
||||||
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||||
|
@ -23,9 +25,10 @@ class ApplicationWrapper extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FutureBuilder(
|
return FutureBuilder(
|
||||||
future: Future.wait([
|
future: Future.wait<dynamic>([
|
||||||
SharedPreferences.getInstance(),
|
SharedPreferences.getInstance(),
|
||||||
const LightSensorService(LocalPlatform()).hasSensor(),
|
const LightSensorService(LocalPlatform()).hasSensor(),
|
||||||
|
const RemoteConfigService().activeAndFetchFeatures(),
|
||||||
]),
|
]),
|
||||||
builder: (_, snapshot) {
|
builder: (_, snapshot) {
|
||||||
if (snapshot.data != null) {
|
if (snapshot.data != null) {
|
||||||
|
@ -38,16 +41,19 @@ class ApplicationWrapper extends StatelessWidget {
|
||||||
hapticsService: const HapticsService(),
|
hapticsService: const HapticsService(),
|
||||||
lightSensorService: const LightSensorService(LocalPlatform()),
|
lightSensorService: const LightSensorService(LocalPlatform()),
|
||||||
permissionsService: const PermissionsService(),
|
permissionsService: const PermissionsService(),
|
||||||
|
remoteConfigService: const RemoteConfigService(),
|
||||||
userPreferencesService: userPreferencesService,
|
userPreferencesService: userPreferencesService,
|
||||||
volumeEventsService: const VolumeEventsService(LocalPlatform()),
|
volumeEventsService: const VolumeEventsService(LocalPlatform()),
|
||||||
child: EquipmentProfileProvider(
|
child: RemoteConfig(
|
||||||
storageService: iapService,
|
child: EquipmentProfileProvider(
|
||||||
child: FilmsProvider(
|
|
||||||
storageService: iapService,
|
storageService: iapService,
|
||||||
child: UserPreferencesProvider(
|
child: FilmsProvider(
|
||||||
hasLightSensor: hasLightSensor,
|
storageService: iapService,
|
||||||
userPreferencesService: userPreferencesService,
|
child: UserPreferencesProvider(
|
||||||
child: child,
|
hasLightSensor: hasLightSensor,
|
||||||
|
userPreferencesService: userPreferencesService,
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
5
lib/data/models/feature.dart
Normal file
5
lib/data/models/feature.dart
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
enum Feature { unlockProFeaturesText }
|
||||||
|
|
||||||
|
const featuresDefaultValues = {
|
||||||
|
Feature.unlockProFeaturesText: false,
|
||||||
|
};
|
42
lib/data/remote_config_service.dart
Normal file
42
lib/data/remote_config_service.dart
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
|
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:flutter/foundation.dart';
|
||||||
|
import 'package:lightmeter/data/models/feature.dart';
|
||||||
|
|
||||||
|
class RemoteConfigService {
|
||||||
|
const RemoteConfigService();
|
||||||
|
|
||||||
|
Future<void> activeAndFetchFeatures() async {
|
||||||
|
final FirebaseRemoteConfig remoteConfig = FirebaseRemoteConfig.instance;
|
||||||
|
const cacheStaleDuration = kDebugMode ? Duration(minutes: 1) : Duration(hours: 12);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await remoteConfig.setConfigSettings(
|
||||||
|
RemoteConfigSettings(
|
||||||
|
fetchTimeout: const Duration(seconds: 15),
|
||||||
|
minimumFetchInterval: cacheStaleDuration,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await remoteConfig.setDefaults(featuresDefaultValues.map((key, value) => MapEntry(key.name, value)));
|
||||||
|
await remoteConfig.activate();
|
||||||
|
await remoteConfig.ensureInitialized();
|
||||||
|
unawaited(remoteConfig.fetch());
|
||||||
|
|
||||||
|
log('Firebase remote config initialized successfully');
|
||||||
|
} on FirebaseException catch (e) {
|
||||||
|
_logError('Firebase exception during Firebase Remote Config initialization: $e');
|
||||||
|
} on Exception catch (e) {
|
||||||
|
_logError('Error during Firebase Remote Config initialization: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isEnabled(Feature feature) => FirebaseRemoteConfig.instance.getBool(feature.name);
|
||||||
|
|
||||||
|
void _logError(dynamic throwable, {StackTrace? stackTrace}) {
|
||||||
|
FirebaseCrashlytics.instance.recordError(throwable, stackTrace);
|
||||||
|
}
|
||||||
|
}
|
17
lib/providers/remote_config_provider.dart
Normal file
17
lib/providers/remote_config_provider.dart
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:lightmeter/data/models/feature.dart';
|
||||||
|
import 'package:lightmeter/providers/services_provider.dart';
|
||||||
|
|
||||||
|
class RemoteConfig extends InheritedWidget {
|
||||||
|
const RemoteConfig({
|
||||||
|
super.key,
|
||||||
|
required super.child,
|
||||||
|
});
|
||||||
|
|
||||||
|
static bool isEnabled(BuildContext context, Feature feature) {
|
||||||
|
return ServicesProvider.of(context).remoteConfigService.isEnabled(feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotify(RemoteConfig oldWidget) => true;
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ import 'package:lightmeter/data/caffeine_service.dart';
|
||||||
import 'package:lightmeter/data/haptics_service.dart';
|
import 'package:lightmeter/data/haptics_service.dart';
|
||||||
import 'package:lightmeter/data/light_sensor_service.dart';
|
import 'package:lightmeter/data/light_sensor_service.dart';
|
||||||
import 'package:lightmeter/data/permissions_service.dart';
|
import 'package:lightmeter/data/permissions_service.dart';
|
||||||
|
import 'package:lightmeter/data/remote_config_service.dart';
|
||||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||||
import 'package:lightmeter/data/volume_events_service.dart';
|
import 'package:lightmeter/data/volume_events_service.dart';
|
||||||
import 'package:lightmeter/environment.dart';
|
import 'package:lightmeter/environment.dart';
|
||||||
|
@ -14,6 +15,7 @@ class ServicesProvider extends InheritedWidget {
|
||||||
final HapticsService hapticsService;
|
final HapticsService hapticsService;
|
||||||
final LightSensorService lightSensorService;
|
final LightSensorService lightSensorService;
|
||||||
final PermissionsService permissionsService;
|
final PermissionsService permissionsService;
|
||||||
|
final RemoteConfigService remoteConfigService;
|
||||||
final UserPreferencesService userPreferencesService;
|
final UserPreferencesService userPreferencesService;
|
||||||
final VolumeEventsService volumeEventsService;
|
final VolumeEventsService volumeEventsService;
|
||||||
|
|
||||||
|
@ -23,6 +25,7 @@ class ServicesProvider extends InheritedWidget {
|
||||||
required this.hapticsService,
|
required this.hapticsService,
|
||||||
required this.lightSensorService,
|
required this.lightSensorService,
|
||||||
required this.permissionsService,
|
required this.permissionsService,
|
||||||
|
required this.remoteConfigService,
|
||||||
required this.userPreferencesService,
|
required this.userPreferencesService,
|
||||||
required this.volumeEventsService,
|
required this.volumeEventsService,
|
||||||
required super.child,
|
required super.child,
|
||||||
|
|
|
@ -13,8 +13,9 @@ dependencies:
|
||||||
clipboard: 0.1.3
|
clipboard: 0.1.3
|
||||||
dynamic_color: 1.6.6
|
dynamic_color: 1.6.6
|
||||||
exif: 3.1.4
|
exif: 3.1.4
|
||||||
firebase_core: 2.14.0
|
firebase_core: 2.20.0
|
||||||
firebase_crashlytics: 3.3.3
|
firebase_crashlytics: 3.4.2
|
||||||
|
firebase_remote_config: 4.3.2
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_bloc: 8.1.3
|
flutter_bloc: 8.1.3
|
||||||
|
@ -26,7 +27,7 @@ dependencies:
|
||||||
m3_lightmeter_iap:
|
m3_lightmeter_iap:
|
||||||
git:
|
git:
|
||||||
url: "https://github.com/vodemn/m3_lightmeter_iap"
|
url: "https://github.com/vodemn/m3_lightmeter_iap"
|
||||||
ref: v0.5.0
|
ref: v0.6.2
|
||||||
m3_lightmeter_resources:
|
m3_lightmeter_resources:
|
||||||
git:
|
git:
|
||||||
url: "https://github.com/vodemn/m3_lightmeter_resources"
|
url: "https://github.com/vodemn/m3_lightmeter_resources"
|
||||||
|
@ -56,7 +57,7 @@ dev_dependencies:
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
assets:
|
assets:
|
||||||
- assets/camera_stub_image.jpg
|
- assets/camera_stub_image.jpg
|
||||||
|
|
||||||
flutter_intl:
|
flutter_intl:
|
||||||
|
|
Loading…
Reference in a new issue