ios: Check if running on a physcial device

Accordingly we switch off analytics.
This commit is contained in:
Vishesh Handa
2019-06-14 17:50:08 +02:00
parent 89f7c10ba9
commit df0d0ed169

View File

@ -1,3 +1,5 @@
import 'dart:io';
import 'package:device_info/device_info.dart'; import 'package:device_info/device_info.dart';
import 'package:firebase_analytics/firebase_analytics.dart'; import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_analytics/observer.dart'; import 'package:firebase_analytics/observer.dart';
@ -70,17 +72,26 @@ class JournalApp extends StatelessWidget {
// Check if in debugMode or not a real device // Check if in debugMode or not a real device
// //
assert(JournalApp.isInDebugMode = true); assert(JournalApp.isInDebugMode = true);
var isPhysicalDevice = true;
try { try {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; if (Platform.isAndroid) {
if (androidInfo.isPhysicalDevice == false) { var info = await deviceInfo.androidInfo;
print("Not running in a physcial device"); isPhysicalDevice = info.isPhysicalDevice;
JournalApp.isInDebugMode = true; } else if (Platform.isIOS) {
var info = await deviceInfo.iosInfo;
isPhysicalDevice = info.isPhysicalDevice;
} }
} catch (e) { } catch (e) {
print(e); print(e);
} }
if (isPhysicalDevice == false) {
print("Not running in a physcial device");
JournalApp.isInDebugMode = true;
}
bool should = (JournalApp.isInDebugMode == false); bool should = (JournalApp.isInDebugMode == false);
should = should && (await shouldEnableAnalytics()); should = should && (await shouldEnableAnalytics());