@@ -29,12 +29,8 @@ class _MyAppState extends State<MyApp> {
29
29
"ddf1949adb3751a25c71cb106b4201eaba9960cbc57e814ffd97ce7d381b0e24c07955a4cdd612f90854198ea600bc15939c182f72308159974b88d5107fe310" )
30
30
.then ((value) => {print ("Setup result: $value " )});
31
31
32
- _contextSdkPlugin.setGlobalCustomSignals ({
33
- 'string' : 'string' ,
34
- 'int' : 12 ,
35
- 'bool' : true ,
36
- 'float' : 1.124
37
- });
32
+ _contextSdkPlugin.setGlobalCustomSignals (
33
+ {'string' : 'string' , 'int' : 12 , 'bool' : true , 'float' : 1.124 });
38
34
}
39
35
40
36
// Platform messages are asynchronous, so we initialize in an async method.
@@ -80,7 +76,7 @@ class _MyAppState extends State<MyApp> {
80
76
})
81
77
},
82
78
child: const Text ('Track Event' )),
83
- ElevatedButton (
79
+ ElevatedButton (
84
80
onPressed: () => {
85
81
_contextSdkPlugin.trackPageView ("my-page" , {
86
82
'string' : 'string' ,
@@ -90,7 +86,7 @@ class _MyAppState extends State<MyApp> {
90
86
})
91
87
},
92
88
child: const Text ('Track Page View' )),
93
- ElevatedButton (
89
+ ElevatedButton (
94
90
onPressed: () => {
95
91
_contextSdkPlugin.trackUserAction ("my-action" , {
96
92
'string' : 'string' ,
@@ -100,9 +96,9 @@ class _MyAppState extends State<MyApp> {
100
96
})
101
97
},
102
98
child: const Text ('Track User Action' )),
103
- ElevatedButton (
99
+ ElevatedButton (
104
100
onPressed: () async => {
105
- _contextSdkPlugin.calibrate ("my_flow" , null , {
101
+ _contextSdkPlugin.calibrate ("my_flow" , customSignals : {
106
102
'string' : 'string' ,
107
103
'int' : 14 ,
108
104
'bool' : true ,
@@ -119,69 +115,102 @@ class _MyAppState extends State<MyApp> {
119
115
})
120
116
},
121
117
child: const Text ('Calibrate' )),
122
- ElevatedButton (
118
+ ElevatedButton (
123
119
onPressed: () async => {
124
- _contextSdkPlugin.optimize ("my_flow" , null , {
125
- 'string' : 'string' ,
126
- 'int' : 14 ,
127
- 'bool' : true ,
128
- 'float' : 1.124
129
- }, (value) async {
130
- print ("Optimized context: ${await value .validate ()}" );
131
- value.appendOutcomeMetadata ({
120
+ _contextSdkPlugin.optimize ("my_flow" , (context) async {
121
+ print ("Optimized context: ${await context .validate ()}" );
122
+ context.appendOutcomeMetadata ({
132
123
'string' : 'string' ,
133
124
'int' : 14 ,
134
125
'bool' : true ,
135
126
'float' : 1.124
136
127
});
137
- value .log (Outcome .positive);
128
+ await context .log (Outcome .positive);
138
129
})
139
130
},
140
131
child: const Text ('Optimize' )),
141
- ElevatedButton (
132
+ ElevatedButton (
142
133
onPressed: () async => {
143
- _contextSdkPlugin.fetchContext ("my_flow" , 3 , {
134
+ _contextSdkPlugin.optimize ("my_flow" , customSignals : {
144
135
'string' : 'string' ,
145
136
'int' : 14 ,
146
137
'bool' : true ,
147
138
'float' : 1.124
148
- }). then ((value ) async {
149
- print ("Fetch context: ${await value .validate ()}" );
150
- value .appendOutcomeMetadata ({
139
+ }, (context ) async {
140
+ print ("Optimized context: ${await context .validate ()}" );
141
+ context .appendOutcomeMetadata ({
151
142
'string' : 'string' ,
152
143
'int' : 14 ,
153
144
'bool' : true ,
154
145
'float' : 1.124
155
146
});
156
- value .log (Outcome .positive);
147
+ await context .log (Outcome .positive);
157
148
})
158
149
},
159
- child: const Text ('Fetch Context ' )),
160
- ElevatedButton (
150
+ child: const Text ('Optimize (Custom Signals) ' )),
151
+ ElevatedButton (
161
152
onPressed: () async => {
162
- _contextSdkPlugin.fetchContext ("my_flow" , 3 , {
163
- 'string' : 'string' ,
164
- 'int' : 14 ,
165
- 'bool' : true ,
166
- 'float' : 1.124
167
- }).then ((value) async {
168
- print ("Instant context: ${await value .validate ()}" );
169
- value.appendOutcomeMetadata ({
153
+ _contextSdkPlugin.optimize ("my_flow" , maxDelay: 0 ,
154
+ (context) async {
155
+ print ("Optimized context: ${await context .validate ()}" );
156
+ context.appendOutcomeMetadata ({
170
157
'string' : 'string' ,
171
158
'int' : 14 ,
172
159
'bool' : true ,
173
160
'float' : 1.124
174
161
});
175
- value .log (Outcome .positive);
162
+ await context .log (Outcome .positive);
176
163
})
177
164
},
178
- child: const Text ('Instant Context ' )),
179
- ElevatedButton (
165
+ child: const Text ('Optimize (Instant) ' )),
166
+ ElevatedButton (
180
167
onPressed: () async => {
181
- _contextSdkPlugin.recentContext ("my_flow" ).then ((value) async {
182
- print ("Recent context: ${await value ?.validate () ?? "No Context Found" }" );
168
+ _contextSdkPlugin.fetchContext ("my_flow" , 3 ,
169
+ customSignals: {
170
+ 'string' : 'string' ,
171
+ 'int' : 14 ,
172
+ 'bool' : true ,
173
+ 'float' : 1.124
174
+ }).then ((value) async {
175
+ print ("Fetch context: ${await value .validate ()}" );
176
+ value.appendOutcomeMetadata ({
177
+ 'string' : 'string' ,
178
+ 'int' : 14 ,
179
+ 'bool' : true ,
180
+ 'float' : 1.124
181
+ });
182
+ value.log (Outcome .positive);
183
183
})
184
184
},
185
+ child: const Text ('Fetch Context' )),
186
+ ElevatedButton (
187
+ onPressed: () async {
188
+ final context =
189
+ await _contextSdkPlugin.instantContext ("my_flow" , 3 );
190
+ print ("Instant context: ${await context .validate ()}" );
191
+ if (await context.shouldUpsell ()) {
192
+ await context.appendOutcomeMetadata ({
193
+ 'string' : 'string' ,
194
+ 'int' : 14 ,
195
+ 'bool' : true ,
196
+ 'float' : 1.124
197
+ });
198
+ await context.log (Outcome .positive);
199
+ } else {
200
+ await context.log (Outcome .skipped);
201
+ }
202
+ },
203
+ child: const Text ('Instant Context' )),
204
+ ElevatedButton (
205
+ onPressed: () async {
206
+ final context =
207
+ await _contextSdkPlugin.recentContext ("my_flow" );
208
+ if (context != null ) {
209
+ print ("Recent context: ${await context .validate ()}" );
210
+ } else {
211
+ print ("No recent context found" );
212
+ }
213
+ },
185
214
child: const Text ('Recent Context' )),
186
215
],
187
216
)),
0 commit comments