-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
flutter_appcenter_bundle.dart
75 lines (63 loc) · 2.28 KB
/
flutter_appcenter_bundle.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import 'dart:async';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
const _methodChannelName = 'com.github.wolfteam.genshindb';
const _methodChannel = MethodChannel(_methodChannelName);
/// Static class that provides AppCenter APIs
class AppCenter {
/// Start appcenter functionalities
static Future<void> startAsync({
@required String appSecretAndroid,
@required String appSecretIOS,
bool enableAnalytics = true,
bool enableCrashes = true,
bool enableDistribute = false,
bool usePrivateDistributeTrack = false,
}) async {
String appsecret;
if (Platform.isAndroid) {
appsecret = appSecretAndroid;
} else if (Platform.isIOS) {
appsecret = appSecretIOS;
} else {
throw UnsupportedError('Current platform is not supported.');
}
if (appsecret == null || appsecret.isEmpty) {
return;
}
await configureAnalyticsAsync(enabled: enableAnalytics);
await configureCrashesAsync(enabled: enableCrashes);
await _methodChannel.invokeMethod('start', <String, dynamic>{
'secret': appsecret.trim(),
'usePrivateTrack': usePrivateDistributeTrack,
});
}
/// Track events
static Future<void> trackEventAsync(String name, [Map<String, String> properties]) async {
await _methodChannel.invokeMethod('trackEvent', <String, dynamic>{
'name': name,
'properties': properties ?? <String, String>{},
});
}
/// Check whether analytics is enalbed
static Future<bool> isAnalyticsEnabledAsync() async {
return _methodChannel.invokeMethod('isAnalyticsEnabled');
}
/// Get appcenter installation id
static Future<String> getInstallIdAsync() async {
return _methodChannel.invokeMethod('getInstallId').then((r) => r as String);
}
/// Enable or disable analytics
static Future configureAnalyticsAsync({@required enabled}) async {
await _methodChannel.invokeMethod('configureAnalytics', enabled);
}
/// Check whether crashes is enabled
static Future<bool> isCrashesEnabledAsync() async {
return _methodChannel.invokeMethod('isCrashesEnabled');
}
/// Enable or disable appcenter crash reports
static Future configureCrashesAsync({@required enabled}) async {
await _methodChannel.invokeMethod('configureCrashes', enabled);
}
}