From 40a12b8af167d0ef54ee22b0408f37fc4ad7403e Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Sat, 16 Feb 2019 13:56:23 +0100 Subject: [PATCH] Consider emulated devices to be debug devices So do not run analytics on them. --- lib/app.dart | 19 +++++++++++++------ pubspec.lock | 7 +++++++ pubspec.yaml | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index 382959ab..5032cd24 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -1,3 +1,4 @@ +import 'package:device_info/device_info.dart'; import 'package:firebase_analytics/firebase_analytics.dart'; import 'package:firebase_analytics/observer.dart'; import 'package:flutter/material.dart'; @@ -25,6 +26,17 @@ class JournalApp extends StatelessWidget { var remoteGitRepoSubFolder = pref.getString("remoteGitRepoSubFolder") ?? ""; var onBoardingCompleted = pref.getBool("onBoardingCompleted") ?? false; + // + // Check if in debugMode or not a real device + // + assert(JournalApp.isInDebugMode = true); + DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); + AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; + if (androidInfo.isPhysicalDevice == false) { + print("Not running in a physcial device"); + JournalApp.isInDebugMode = true; + } + if (JournalApp.isInDebugMode) { if (JournalApp.analytics.android != null) { JournalApp.analytics.android.setAnalyticsCollectionEnabled(false); @@ -62,12 +74,7 @@ class JournalApp extends StatelessWidget { static FirebaseAnalyticsObserver observer = FirebaseAnalyticsObserver(analytics: analytics); - static bool get isInDebugMode { - bool inDebugMode = false; - assert(inDebugMode = true); - return inDebugMode; - } - + static bool isInDebugMode = false; static SharedPreferences preferences; @override diff --git a/pubspec.lock b/pubspec.lock index dcfb965b..cb72890f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -87,6 +87,13 @@ packages: url: "https://github.com/MarkOSullivan94/dart_config.git" source: git version: "0.5.0" + device_info: + dependency: "direct main" + description: + name: device_info + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.0+1" dots_indicator: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index ea7812f7..7c80459e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,6 +19,7 @@ dependencies: badges: ^0.0.6 share: ^0.6.0+1 launch_review: ^1.0.1 + device_info: ^0.4.0+1 dev_dependencies: flutter_launcher_icons: "^0.7.0"