Skip to content

Commit 6c71ab3

Browse files
committed
add putAllContext method
1 parent 61ac22d commit 6c71ab3

File tree

6 files changed

+49
-4
lines changed

6 files changed

+49
-4
lines changed

android/src/main/kotlin/com/example/confidence_flutter_sdk/ConfidenceFlutterSdkPlugin.kt

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import com.spotify.confidence.Confidence
55
import com.spotify.confidence.ConfidenceFactory
66
import com.spotify.confidence.ConfidenceValue
77
import com.spotify.confidence.FlagResolution
8-
import com.spotify.confidence.cache.DiskStorage
9-
import com.spotify.confidence.client.ConfidenceValueMap
10-
import com.spotify.confidence.client.ResolveFlags
118
import com.spotify.confidence.client.SdkMetadata
129
import io.flutter.embedding.engine.plugins.FlutterPlugin
1310
import io.flutter.embedding.engine.plugins.activity.ActivityAware
@@ -111,6 +108,12 @@ class ConfidenceFlutterSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAwar
111108
confidence.putContext(key, value)
112109
result.success(null)
113110
}
111+
"putAllContext" -> {
112+
val wrappedContext = call.argument<Map<String, Map<String, Any>>>("context")!!
113+
val context: Map<String, ConfidenceValue> = wrappedContext.mapValues { (_, value) -> value.convert() }
114+
confidence.putContext(context)
115+
result.success(null)
116+
}
114117
"track" -> {
115118
val eventName = call.argument<String>("eventName")!!
116119
val wrappedData = call.argument<Map<String, Map<String, Any>>>("data")!!

example/lib/main.dart

+7-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ class _MyAppState extends State<MyApp> {
4545
try {
4646
await dotenv.load(fileName: ".env");
4747
await _confidenceFlutterSdkPlugin.setup(dotenv.env["API_KEY"]!);
48-
await _confidenceFlutterSdkPlugin.putContext("targeting_key", "random");
48+
await _confidenceFlutterSdkPlugin.putAllContext({
49+
"my_bool": false,
50+
"my_int": 1,
51+
"my_double": 1.1,
52+
"my_map": {"key": "value"},
53+
"my_list": ["value1", "value2"]
54+
});
4955
await _confidenceFlutterSdkPlugin.fetchAndActivate();
5056
object =
5157
(_confidenceFlutterSdkPlugin.getObject("hawkflag", <String, dynamic>{})).toString();

ios/Classes/ConfidenceFlutterSdkPlugin.swift

+13
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ public class ConfidenceFlutterSdkPlugin: NSObject, FlutterPlugin {
7979
confidence?.putContext(key: key, value: value)
8080
result("")
8181
break;
82+
case "putAllContext":
83+
guard let args = call.arguments as? Dictionary<String, Dictionary<String, Any>> else {
84+
result("")
85+
return
86+
}
87+
let context = args["context"] as! Dictionary<String, Dictionary<String, Any>>
88+
let map: ConfidenceStruct = context.mapValues { wrappedValue in
89+
let type = wrappedValue["type"] as! String
90+
return convertValue(type, wrappedValue["value"]!)
91+
}
92+
confidence?.putContext(context: map)
93+
result("")
94+
break;
8295
case "track":
8396
guard let args = call.arguments as? Dictionary<String, Any> else {
8497
return

lib/confidence_flutter_sdk.dart

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ class ConfidenceFlutterSdk {
1616
}
1717
}
1818

19+
Future<void> putAllContext(Map<String, dynamic> context) async {
20+
await ConfidenceFlutterSdkPlatform.instance.putAllContext(context);
21+
if(isInitialized) {
22+
await fetchAndActivate();
23+
}
24+
}
25+
1926
void track(String eventName, Map<String, dynamic> data) {
2027
ConfidenceFlutterSdkPlatform.instance.track(eventName, data);
2128
}

lib/confidence_flutter_sdk_method_channel.dart

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ class MethodChannelConfidenceFlutterSdk extends ConfidenceFlutterSdkPlatform {
3535
);
3636
}
3737

38+
@override
39+
Future<void> putAllContext(Map<String, dynamic> context) async {
40+
final wrappedContext = context.map((key, value) {
41+
return MapEntry(key, toTypedValue(value));
42+
});
43+
await methodChannel
44+
.invokeMethod<void>(
45+
'putAllContext',
46+
{'context': wrappedContext}
47+
);
48+
}
49+
3850
@override
3951
void track(String eventName, Map<String, dynamic> data) {
4052
final wrappedData = data.map((key, value) {

lib/confidence_flutter_sdk_platform_interface.dart

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ abstract class ConfidenceFlutterSdkPlatform extends PlatformInterface {
4343
throw UnimplementedError('putContext() has not been implemented.');
4444
}
4545

46+
Future<void> putAllContext(Map<String, dynamic> context) async {
47+
throw UnimplementedError('putAllContext() has not been implemented.');
48+
}
49+
4650
Future<bool> isStorageEmpty() {
4751
throw UnimplementedError('isStorageEmpty() has not been implemented.');
4852
}

0 commit comments

Comments
 (0)