|
1 | | -import 'dart:async'; |
2 | | -import 'dart:io'; |
| 1 | +// This file exists to support old way to import package: 'package:qonversion_flutter/qonversion.dart'. |
| 2 | +// Recommended way to import package no: 'package:qonversion_flutter/qonversion_flutter.dart'. |
3 | 3 |
|
4 | | -import 'package:flutter/foundation.dart'; |
5 | | -import 'package:flutter/services.dart'; |
6 | | - |
7 | | -import 'src/constants.dart'; |
8 | | - |
9 | | -enum QAttributionProvider { appsFlyer, branch } |
10 | | - |
11 | | -class Qonversion { |
12 | | - static const MethodChannel _channel = |
13 | | - const MethodChannel('qonversion_flutter_sdk'); |
14 | | - |
15 | | - /// Launches Qonversion SDK with the given API keys for each platform: |
16 | | - /// [androidApiKey] and [iosApiKey] respectively, |
17 | | - /// you can get one in your account on qonversion.io. |
18 | | - /// |
19 | | - /// Returns `userId` for Ads integrations. |
20 | | - /// |
21 | | - /// **Warning**: |
22 | | - /// Qonversion will track any purchase events (trials, subscriptions, basic purchases) automatically. |
23 | | - static Future<String> launch({ |
24 | | - @required String androidApiKey, |
25 | | - @required String iosApiKey, |
26 | | - String userId, |
27 | | - }) async { |
28 | | - final apiKey = _obtainPlatformApiKey( |
29 | | - androidApiKey: androidApiKey, |
30 | | - iosApiKey: iosApiKey, |
31 | | - ); |
32 | | - |
33 | | - final args = { |
34 | | - Constants.kApiKey: apiKey, |
35 | | - Constants.kUserId: userId, |
36 | | - }; |
37 | | - |
38 | | - final uid = await _channel.invokeMethod(Constants.mLaunch, args); |
39 | | - |
40 | | - return uid; |
41 | | - } |
42 | | - |
43 | | - Future<String> trackPurchase( |
44 | | - Map<String, dynamic> details, Map<String, dynamic> purchase) async { |
45 | | - final args = { |
46 | | - Constants.kDetails: details, |
47 | | - Constants.kPurchase: purchase, |
48 | | - }; |
49 | | - |
50 | | - final uid = await _channel.invokeMethod(Constants.mTrackPurchase, args); |
51 | | - |
52 | | - return uid; |
53 | | - } |
54 | | - |
55 | | - /// Launches Qonversion SDK with the given API keys for each platform: |
56 | | - /// [androidApiKey] and [iosApiKey] respectively, |
57 | | - /// you can get one in your account on qonversion.io. |
58 | | - /// |
59 | | - /// [onComplete] will return `uid` for Ads integrations. |
60 | | - /// |
61 | | - /// **Warning**: |
62 | | - /// Qonversion will track any purchase events (trials, subscriptions, basic purchases) automatically. |
63 | | - @Deprecated("Use `launch` method instead") |
64 | | - static Future<void> launchWith({ |
65 | | - String androidApiKey, |
66 | | - String iosApiKey, |
67 | | - void Function(String) onComplete, |
68 | | - }) async { |
69 | | - final key = _obtainPlatformApiKey( |
70 | | - androidApiKey: androidApiKey, |
71 | | - iosApiKey: iosApiKey, |
72 | | - ); |
73 | | - |
74 | | - final args = {Constants.kApiKey: key}; |
75 | | - final uid = |
76 | | - await _channel.invokeMethod(Constants.mLaunchWithKeyCompletion, args); |
77 | | - |
78 | | - onComplete(uid); |
79 | | - } |
80 | | - |
81 | | - /// Launches Qonversion SDK with the given API keys for each platform: |
82 | | - /// [androidApiKey] and [iosApiKey] respectively, |
83 | | - /// you can get one in your account on qonversion.io. |
84 | | - /// |
85 | | - /// Sets client side [userid] (instead of Qonversion user-id) that will be used for matching data in the third party data. |
86 | | - @Deprecated("Use `launch` method instead") |
87 | | - static Future<void> launchWithClientSideUserId( |
88 | | - String userID, { |
89 | | - String androidApiKey, |
90 | | - String iosApiKey, |
91 | | - }) { |
92 | | - final key = _obtainPlatformApiKey( |
93 | | - androidApiKey: androidApiKey, iosApiKey: iosApiKey); |
94 | | - |
95 | | - final args = { |
96 | | - Constants.kApiKey: key, |
97 | | - Constants.kUserId: userID, |
98 | | - }; |
99 | | - |
100 | | - return _channel.invokeMethod(Constants.mLaunchWithKeyUserId, args); |
101 | | - } |
102 | | - |
103 | | - /// **Don't use with autoTrackPurchases: false** now. |
104 | | - /// Functionality is under development yet. |
105 | | - /// |
106 | | - /// Launches Qonversion SDK with the given API keys for each platform: |
107 | | - /// [androidApiKey] and [iosApiKey] respectively, |
108 | | - /// you can get one in your account on qonversion.io. |
109 | | - /// |
110 | | - /// With [autoTrackPurchases] parameter turned off you need to call `trackPurchase:transaction:` method. |
111 | | - /// [onComplete] will return `uid` for Ads integrations. |
112 | | - /// **Warning**: |
113 | | - /// Will track any purchase events (trials, subscriptions, basic purchases) automatically. |
114 | | - /// But if `autoTrackPurchases` disabled you need to call `trackPurchase:transaction:` method (under development yet). |
115 | | - /// Otherwise, purchases tracking won't work. |
116 | | - @Deprecated("Use `launch` method instead") |
117 | | - static Future<void> launchWithAutoTrackPurchases( |
118 | | - bool autoTrackPurchases, { |
119 | | - String androidApiKey, |
120 | | - String iosApiKey, |
121 | | - void Function(String) onComplete, |
122 | | - }) async { |
123 | | - final key = _obtainPlatformApiKey( |
124 | | - androidApiKey: androidApiKey, iosApiKey: iosApiKey); |
125 | | - |
126 | | - final args = { |
127 | | - Constants.kApiKey: key, |
128 | | - Constants.kAutoTrackPurchases: autoTrackPurchases, |
129 | | - }; |
130 | | - final uid = await _channel.invokeMethod<String>( |
131 | | - Constants.mLaunchWithKeyAutoTrackPurchasesCompletion, args); |
132 | | - |
133 | | - onComplete(uid); |
134 | | - } |
135 | | - |
136 | | - /// Sends your attribution [data] to the [provider]. |
137 | | - /// |
138 | | - /// [userID], if specified, will also be sent to the provider |
139 | | - static Future<void> addAttributionData( |
140 | | - Map<dynamic, dynamic> data, QAttributionProvider provider) { |
141 | | - final args = { |
142 | | - Constants.kData: data, |
143 | | - Constants.kProvider: describeEnum(provider), |
144 | | - }; |
145 | | - |
146 | | - return _channel.invokeMethod(Constants.mAddAttributionData, args); |
147 | | - } |
148 | | - |
149 | | - static String _obtainPlatformApiKey({ |
150 | | - String androidApiKey, |
151 | | - String iosApiKey, |
152 | | - }) { |
153 | | - String key; |
154 | | - |
155 | | - if (Platform.isAndroid) { |
156 | | - key = androidApiKey; |
157 | | - } else if (Platform.isIOS) { |
158 | | - key = iosApiKey; |
159 | | - } else { |
160 | | - throw Exception('Unsupported platform'); |
161 | | - } |
162 | | - |
163 | | - if (key == null) { |
164 | | - throw Exception( |
165 | | - 'Please provide API key for the platform you are running an app on'); |
166 | | - } |
167 | | - |
168 | | - return key; |
169 | | - } |
170 | | -} |
| 4 | +export 'src/qonversion.dart'; |
| 5 | +export 'src/qa_provider.dart'; |
0 commit comments