Skip to content

Commit e8ca0ad

Browse files
authored
Merge pull request #19 from qonversion/refactoring/structure_update
Refactoring - Remove deprecated methods & update directory/file structure
2 parents a7dbd33 + 263f766 commit e8ca0ad

File tree

5 files changed

+96
-170
lines changed

5 files changed

+96
-170
lines changed

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'dart:async';
33

4-
import 'package:qonversion_flutter/qonversion.dart';
4+
import 'package:qonversion_flutter/qonversion_flutter.dart';
55

66
void main() => runApp(MyApp());
77

lib/qonversion.dart

Lines changed: 4 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,5 @@
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'.
33

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';

lib/qonversion_flutter.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export 'src/qonversion.dart';
2+
export 'src/qa_provider.dart';

lib/src/qa_provider.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enum QAttributionProvider { appsFlyer, branch }

lib/src/qonversion.dart

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import 'dart:async';
2+
import 'dart:io';
3+
4+
import 'package:flutter/foundation.dart';
5+
import 'package:flutter/services.dart';
6+
7+
import 'constants.dart';
8+
import 'qa_provider.dart';
9+
10+
class Qonversion {
11+
static const MethodChannel _channel =
12+
const MethodChannel('qonversion_flutter_sdk');
13+
14+
/// Launches Qonversion SDK with the given API keys for each platform:
15+
/// [androidApiKey] and [iosApiKey] respectively,
16+
/// you can get one in your account on qonversion.io.
17+
///
18+
/// Returns `userId` for Ads integrations.
19+
///
20+
/// **Warning**:
21+
/// Qonversion will track any purchase events (trials, subscriptions, basic purchases) automatically.
22+
static Future<String> launch({
23+
@required String androidApiKey,
24+
@required String iosApiKey,
25+
String userId,
26+
}) async {
27+
final apiKey = _obtainPlatformApiKey(
28+
androidApiKey: androidApiKey,
29+
iosApiKey: iosApiKey,
30+
);
31+
32+
final args = {
33+
Constants.kApiKey: apiKey,
34+
Constants.kUserId: userId,
35+
};
36+
37+
final uid = await _channel.invokeMethod(Constants.mLaunch, args);
38+
39+
return uid;
40+
}
41+
42+
Future<String> trackPurchase(
43+
Map<String, dynamic> details, Map<String, dynamic> purchase) async {
44+
final args = {
45+
Constants.kDetails: details,
46+
Constants.kPurchase: purchase,
47+
};
48+
49+
final uid = await _channel.invokeMethod(Constants.mTrackPurchase, args);
50+
51+
return uid;
52+
}
53+
54+
/// Sends your attribution [data] to the [provider].
55+
///
56+
/// [userID], if specified, will also be sent to the provider
57+
static Future<void> addAttributionData(
58+
Map<dynamic, dynamic> data, QAttributionProvider provider) {
59+
final args = {
60+
Constants.kData: data,
61+
Constants.kProvider: describeEnum(provider),
62+
};
63+
64+
return _channel.invokeMethod(Constants.mAddAttributionData, args);
65+
}
66+
67+
static String _obtainPlatformApiKey({
68+
String androidApiKey,
69+
String iosApiKey,
70+
}) {
71+
String key;
72+
73+
if (Platform.isAndroid) {
74+
key = androidApiKey;
75+
} else if (Platform.isIOS) {
76+
key = iosApiKey;
77+
} else {
78+
throw Exception('Unsupported platform');
79+
}
80+
81+
if (key == null) {
82+
throw Exception(
83+
'Please provide API key for the platform you are running an app on');
84+
}
85+
86+
return key;
87+
}
88+
}

0 commit comments

Comments
 (0)