Created
August 16, 2021 11:58
-
-
Save ddikman/e84f0514963658968a081bcbc6c860e8 to your computer and use it in GitHub Desktop.
Example of a service to help abstract the storage of experimental mode on local device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:firebase_analytics/firebase_analytics.dart'; | |
import 'package:japanese_reading/services/preferences.dart'; | |
class ExperimentalMode { | |
static final cacheStaleKey = 'cache_stale'; | |
static final experimentalModeKey = 'experimental_mode'; | |
final FirebaseAnalytics analytics; | |
final Preferences preferences; | |
ExperimentalMode(this.preferences, this.analytics); | |
get isExperimentalMode => preferences.getBool(experimentalModeKey) ?? false; | |
void setConfigStale(bool isStale) { | |
preferences.set(cacheStaleKey, isStale); | |
} | |
bool isConfigStale() => preferences.getBool(cacheStaleKey) ?? false; | |
void setExperimentalMode(bool experimentalMode) { | |
final value = experimentalMode ? "true" : "false"; | |
preferences.set(experimentalModeKey, experimentalMode); | |
this.analytics.setUserProperty(name: 'experimental_mode', value: value); | |
this.analytics.logEvent(name: 'toggled_experimental_mode', parameters: { 'value': value }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment