Skip to content

Commit 82a2fcf

Browse files
authored
Release 7.0.0
Release 7.0.0
2 parents 8ec4ded + 4a97ae3 commit 82a2fcf

20 files changed

+301
-35
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 7.0.0
2+
* New `userProperties` method to get all the properties set for the current user.
3+
* Renamings of several entities and public methods to make our namings and structure clearer.
4+
15
## 6.1.2
26
* Android 14 support.
37

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ android {
4343

4444
dependencies {
4545
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
46-
implementation "io.qonversion.sandwich:sandwich:2.0.2"
46+
implementation "io.qonversion.sandwich:sandwich:3.0.0"
4747
implementation 'com.google.code.gson:gson:2.9.0'
4848
}

android/src/main/kotlin/com/qonversion/flutter/sdk/qonversion_flutter_sdk/QonversionPlugin.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class QonversionPlugin : MethodCallHandler, FlutterPlugin, ActivityAware {
106106
"offerings" -> {
107107
return offerings(result)
108108
}
109+
"userProperties" -> {
110+
return userProperties(result)
111+
}
109112
"remoteConfig" -> {
110113
return remoteConfig(result)
111114
}
@@ -222,6 +225,10 @@ class QonversionPlugin : MethodCallHandler, FlutterPlugin, ActivityAware {
222225
qonversionSandwich.offerings(result.toJsonResultListener())
223226
}
224227

228+
private fun userProperties(result: Result) {
229+
qonversionSandwich.userProperties(result.toJsonResultListener())
230+
}
231+
225232
private fun remoteConfig(result: Result) {
226233
qonversionSandwich.remoteConfig(result.toJsonResultListener())
227234
}

example/lib/home.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ class _HomeViewState extends State<HomeView> {
9898
child: Text('Set custom userId'),
9999
color: Colors.blue,
100100
textColor: Colors.white,
101-
onPressed: () => Qonversion.getSharedInstance().setProperty(
102-
QUserProperty.customUserId, 'userId')),
101+
onPressed: () => Qonversion.getSharedInstance().setUserProperty(
102+
QUserPropertyKey.customUserId, 'userId')),
103103
),
104104
Padding(
105105
padding: const EdgeInsets.only(

example/lib/params_view.dart

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,31 @@ class ParamsView extends StatelessWidget {
1717
child: Column(
1818
crossAxisAlignment: CrossAxisAlignment.start,
1919
children: [
20+
FlatButton(
21+
child: Text('Get user properties'),
22+
color: Colors.amber,
23+
textColor: Colors.white,
24+
onPressed: () async {
25+
try {
26+
QUserProperties userProperties =
27+
await Qonversion.getSharedInstance().userProperties();
28+
userProperties.properties.forEach((userProperty) {
29+
print('User property - key: ' +
30+
userProperty.key +
31+
', value: ' +
32+
userProperty.value);
33+
});
34+
} catch (e) {
35+
// handle error here
36+
}
37+
},
38+
),
2039
FlatButton(
2140
child: Text('Set User ID'),
2241
color: Colors.green,
2342
textColor: Colors.white,
2443
onPressed: () {
25-
Qonversion.getSharedInstance().setProperty(QUserProperty.customUserId, 'customId');
44+
Qonversion.getSharedInstance().setUserProperty(QUserPropertyKey.customUserId, 'customId');
2645
print('did set user id');
2746
},
2847
),
@@ -31,17 +50,17 @@ class ParamsView extends StatelessWidget {
3150
color: Colors.blue,
3251
textColor: Colors.white,
3352
onPressed: () {
34-
Qonversion.getSharedInstance().setUserProperty('customProperty', 'customValue');
53+
Qonversion.getSharedInstance().setCustomUserProperty('customProperty', 'customValue');
3554
print('did set user property');
3655
},
3756
),
38-
for (final v in QUserProperty.values)
57+
for (final v in QUserPropertyKey.values)
3958
FlatButton(
4059
child: Text('Set ${describeEnum(v)}'),
4160
color: Colors.purple,
4261
textColor: Colors.white,
4362
onPressed: () {
44-
Qonversion.getSharedInstance().setProperty(v, '[email protected]');
63+
Qonversion.getSharedInstance().setUserProperty(v, '[email protected]');
4564
print('did set property');
4665
},
4766
),

ios/Classes/SwiftQonversionPlugin.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ public class SwiftQonversionPlugin: NSObject, FlutterPlugin {
7676
return result(nil)
7777

7878
case "userInfo":
79-
qonversionSandwich?.userInfo(getDefaultCompletion(result))
80-
return result(nil)
79+
return userInfo(result)
80+
81+
case "userProperties":
82+
return userProperties(result)
8183

8284
case "presentCodeRedemptionSheet":
8385
return presentCodeRedemptionSheet(result)
@@ -226,6 +228,14 @@ public class SwiftQonversionPlugin: NSObject, FlutterPlugin {
226228
private func remoteConfig(_ result: @escaping FlutterResult) {
227229
qonversionSandwich?.remoteConfig(getJsonCompletion(result))
228230
}
231+
232+
private func userInfo(_ result: @escaping FlutterResult) {
233+
qonversionSandwich?.userInfo(getDefaultCompletion(result))
234+
}
235+
236+
private func userProperties(_ result: @escaping FlutterResult) {
237+
qonversionSandwich?.userProperties(getJsonCompletion(result))
238+
}
229239

230240
private func restore(_ result: @escaping FlutterResult) {
231241
qonversionSandwich?.restore(getDefaultCompletion(result))

ios/qonversion_flutter.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
s.source_files = 'Classes/**/*'
1717
s.dependency 'Flutter'
1818
s.platform = :ios, '9.0'
19-
s.dependency "QonversionSandwich", "2.0.2"
19+
s.dependency "QonversionSandwich", "3.0.0"
2020

2121
# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
2222
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }

lib/qonversion_flutter.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export 'src/dto/remote_config.dart';
2222
export 'src/dto/screen_presentation_config.dart';
2323
export 'src/dto/screen_presentation_style.dart';
2424
export 'src/dto/user.dart';
25+
export 'src/dto/user_properties.dart';
2526
export 'src/dto/user_property.dart';
27+
export 'src/dto/user_property_key.dart';
2628
export 'src/dto/sk_product/discount_payment_mode.dart';
2729
export 'src/dto/sk_product/subscription_period_unit.dart';
2830
export 'src/qonversion.dart';

lib/src/dto/user_properties.dart

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import 'package:collection/collection.dart' show IterableExtension;
2+
import 'package:json_annotation/json_annotation.dart';
3+
import 'package:qonversion_flutter/qonversion_flutter.dart';
4+
5+
part 'user_properties.g.dart';
6+
7+
@JsonSerializable(createToJson: false)
8+
class QUserProperties {
9+
/// List of all user properties.
10+
@JsonKey(name: "properties")
11+
final List<QUserProperty> properties;
12+
13+
/// List of user properties, set for the Qonversion defined keys.
14+
/// This is a subset of all [properties] list.
15+
/// See [Qonversion.setUserProperty].
16+
final List<QUserProperty> definedProperties;
17+
18+
/// List of user properties, set for custom keys.
19+
/// This is a subset of all [properties] list.
20+
/// See [Qonversion.setCustomUserProperty].
21+
final List<QUserProperty> customProperties;
22+
23+
/// Map of all user properties.
24+
/// This is a flattened version of the [properties] list as a key-value map.
25+
final Map<String, String> flatPropertiesMap;
26+
27+
/// Map of user properties, set for the Qonversion defined keys.
28+
/// This is a flattened version of the [definedProperties] list as a key-value map.
29+
/// See [Qonversion.setUserProperty].
30+
final Map<QUserPropertyKey, String> flatDefinedPropertiesMap;
31+
32+
/// Map of user properties, set for custom keys.
33+
/// This is a flattened version of the [customProperties] list as a key-value map.
34+
/// See [Qonversion.setCustomUserProperty].
35+
final Map<String, String> flatCustomPropertiesMap;
36+
37+
QUserProperties._(
38+
this.properties,
39+
this.definedProperties,
40+
this.customProperties,
41+
this.flatPropertiesMap,
42+
this.flatDefinedPropertiesMap,
43+
this.flatCustomPropertiesMap,
44+
);
45+
46+
factory QUserProperties(List<QUserProperty> properties) {
47+
final List<QUserProperty> definedProperties = properties.whereNot(
48+
(userProperty) => userProperty.definedKey == QUserPropertyKey.custom
49+
).toList();
50+
final List<QUserProperty> customProperties = properties.where(
51+
(userProperty) => userProperty.definedKey == QUserPropertyKey.custom
52+
).toList();
53+
54+
final Map<String, String> flatPropertiesMap = Map.fromIterable(
55+
properties,
56+
key: (userProperty) => userProperty.key,
57+
value: (userProperty) => userProperty.value,
58+
);
59+
60+
final Map<QUserPropertyKey, String> flatDefinedPropertiesMap = Map.fromIterable(
61+
definedProperties,
62+
key: (userProperty) => userProperty.definedKey,
63+
value: (userProperty) => userProperty.value,
64+
);
65+
66+
final Map<String, String> flatCustomPropertiesMap = Map.fromIterable(
67+
customProperties,
68+
key: (userProperty) => userProperty.key,
69+
value: (userProperty) => userProperty.value,
70+
);
71+
72+
return QUserProperties._(
73+
properties,
74+
definedProperties,
75+
customProperties,
76+
flatPropertiesMap,
77+
flatDefinedPropertiesMap,
78+
flatCustomPropertiesMap,
79+
);
80+
}
81+
82+
factory QUserProperties.fromJson(Map<String, dynamic> json) =>
83+
_$QUserPropertiesFromJson(json);
84+
85+
/// Searches for a property with the given property [key] in all properties list.
86+
QUserProperty? getProperty(String key) {
87+
return properties.firstWhereOrNull((userProperty) => userProperty.key == key);
88+
}
89+
90+
/// Searches for a property with the given Qonversion defined property [key]
91+
/// in defined properties list.
92+
QUserProperty? getDefinedProperty(QUserPropertyKey key) {
93+
return definedProperties.firstWhereOrNull((userProperty) => userProperty.definedKey == key);
94+
}
95+
}

lib/src/dto/user_properties.g.dart

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)