Use flutter_runtime_env

Now almost all of the custom Java/iOS code has been moved to plugins.
This commit is contained in:
Vishesh Handa
2019-12-26 16:59:23 +01:00
parent 9153a9f2a1
commit cdd3f8d86c
5 changed files with 11 additions and 45 deletions

View File

@ -40,35 +40,9 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
Context context = getApplicationContext();
final String filesDir = PathUtils.getFilesDir(context);
Log.d("GitJournalAndroid", "Called method " + call.method);
if (call.arguments instanceof Map) {
Map<String, Object> map = (Map<String, Object>) call.arguments;
for (Map.Entry<String, Object> entry : map.entrySet()) {
Object val = entry.getValue();
String objVal = "";
if (val != null) {
objVal = val.toString();
}
Log.d("GitJournalAndroid", ". " + entry.getKey() + ": " + val);
}
}
if (call.method.equals("getBaseDirectory")) {
result.success(filesDir);
return;
} else if (call.method.equals("shouldEnableAnalytics")) {
boolean shouldBe = true;
String testLabSetting = Settings.System.getString(context.getContentResolver(), "firebase.test.lab");
if ("true".equals(testLabSetting)) {
shouldBe = false;
}
if (BuildConfig.DEBUG) {
shouldBe = false;
}
result.success(shouldBe);
return;
}
result.notImplemented();

View File

@ -7,13 +7,13 @@ import 'package:firebase_analytics/observer.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:path/path.dart' as p;
import 'package:flutter_runtime_env/flutter_runtime_env.dart' as runtime_env;
import 'package:git_bindings/git_bindings.dart';
import 'package:gitjournal/apis/git.dart';
import 'package:gitjournal/settings.dart';
import 'package:gitjournal/state_container.dart';
import 'package:gitjournal/utils.dart';
import 'package:gitjournal/appstate.dart';
import 'package:gitjournal/themes.dart';
@ -62,10 +62,7 @@ class JournalApp extends StatelessWidget {
}
static void _enableAnalyticsIfPossible() async {
//
// Check if in debugMode or not a real device
//
assert(JournalApp.isInDebugMode = true);
JournalApp.isInDebugMode = runtime_env.isInDebugMode();
var isPhysicalDevice = true;
try {
@ -82,12 +79,11 @@ class JournalApp extends StatelessWidget {
}
if (isPhysicalDevice == false) {
Fimber.d("Not running in a physcial device");
JournalApp.isInDebugMode = true;
}
bool should = (JournalApp.isInDebugMode == false);
should = should && (await shouldEnableAnalytics());
should = should && (await runtime_env.inFirebaseTestLab());
Fimber.d("Analytics Collection: $should");
JournalApp.analytics.setAnalyticsCollectionEnabled(should);

View File

@ -1,6 +1,5 @@
import 'package:fimber/fimber.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:package_info/package_info.dart';
import 'package:flushbar/flushbar.dart';
@ -23,17 +22,6 @@ Future<String> getVersionString() async {
return versionText;
}
Future<bool> shouldEnableAnalytics() async {
try {
const _platform = MethodChannel('gitjournal.io/git');
final bool result = await _platform.invokeMethod('shouldEnableAnalytics');
return result;
} on MissingPluginException catch (e) {
Fimber.d("shouldEnableAnalytics: $e");
return false;
}
}
void showUndoDeleteSnackbar(
BuildContext context,
StateContainerState stateContainer,

View File

@ -193,6 +193,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.2"
flutter_runtime_env:
dependency: "direct main"
description:
name: flutter_runtime_env
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1"
flutter_staggered_grid_view:
dependency: "direct main"
description:

View File

@ -32,6 +32,7 @@ dependencies:
provider: ^3.2.0
git_bindings: ^0.0.6
fetch_app_logs: ^0.0.2
flutter_runtime_env: ^0.0.1
dev_dependencies:
flutter_launcher_icons: "^0.7.2"