Disable analytics in debug mode

Sadly we can only do this in Android, there doesn't seem to be a way to
disable it on iOS.

https://github.com/flutter/flutter/issues/21063
This commit is contained in:
Vishesh Handa
2019-01-18 12:30:01 +01:00
parent d6d68a5a0f
commit b322e4806d
2 changed files with 13 additions and 1 deletions

View File

@ -11,6 +11,12 @@ class JournalApp extends StatelessWidget {
static FirebaseAnalyticsObserver observer =
FirebaseAnalyticsObserver(analytics: analytics);
static bool get isInDebugMode {
bool inDebugMode = false;
assert(inDebugMode = true);
return inDebugMode;
}
@override
Widget build(BuildContext context) {
final stateContainer = StateContainer.of(context);
@ -30,7 +36,7 @@ class JournalApp extends StatelessWidget {
primaryColorDark: Color(0xFF338a3e),
accentColor: Color(0xff6d4c41),
),
navigatorObservers: <NavigatorObserver>[observer],
navigatorObservers: <NavigatorObserver>[JournalApp.observer],
);
}
}

View File

@ -32,6 +32,12 @@ Future runJournalApp() async {
var pref = await SharedPreferences.getInstance();
var onBoardingCompleted = pref.getBool("onBoardingCompleted") ?? false;
if (JournalApp.isInDebugMode) {
if (JournalApp.analytics.android != null) {
JournalApp.analytics.android.setAnalyticsCollectionEnabled(false);
}
}
runApp(new StateContainer(
onBoardingCompleted: onBoardingCompleted,
child: JournalApp(),