Skip to content

Instantly share code, notes, and snippets.

@ddikman
Created August 16, 2021 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddikman/e84f0514963658968a081bcbc6c860e8 to your computer and use it in GitHub Desktop.
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
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