@@ -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" , null , {
106
102
'string' : 'string' ,
107
103
'int' : 14 ,
108
104
'bool' : true ,
@@ -119,9 +115,9 @@ 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 , {
120
+ _contextSdkPlugin.optimize ("my_flow" , null , {
125
121
'string' : 'string' ,
126
122
'int' : 14 ,
127
123
'bool' : true ,
@@ -138,9 +134,9 @@ class _MyAppState extends State<MyApp> {
138
134
})
139
135
},
140
136
child: const Text ('Optimize' )),
141
- ElevatedButton (
137
+ ElevatedButton (
142
138
onPressed: () async => {
143
- _contextSdkPlugin.fetchContext ("my_flow" , 3 , {
139
+ _contextSdkPlugin.fetchContext ("my_flow" , 3 , {
144
140
'string' : 'string' ,
145
141
'int' : 14 ,
146
142
'bool' : true ,
@@ -157,31 +153,34 @@ class _MyAppState extends State<MyApp> {
157
153
})
158
154
},
159
155
child: const Text ('Fetch Context' )),
160
- ElevatedButton (
161
- 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 ({
170
- 'string' : 'string' ,
171
- 'int' : 14 ,
172
- 'bool' : true ,
173
- 'float' : 1.124
174
- });
175
- value.log (Outcome .positive);
176
- })
177
- },
156
+ ElevatedButton (
157
+ onPressed: () async {
158
+ final context = await _contextSdkPlugin.instantContext (
159
+ "my_flow" , 3 , null );
160
+ print ("Instant context: ${await context .validate ()}" );
161
+ if (await context.shouldUpsell ()) {
162
+ await context.appendOutcomeMetadata ({
163
+ 'string' : 'string' ,
164
+ 'int' : 14 ,
165
+ 'bool' : true ,
166
+ 'float' : 1.124
167
+ });
168
+ await context.log (Outcome .positive);
169
+ } else {
170
+ await context.log (Outcome .skipped);
171
+ }
172
+ },
178
173
child: const Text ('Instant Context' )),
179
- ElevatedButton (
180
- onPressed: () async => {
181
- _contextSdkPlugin.recentContext ("my_flow" ).then ((value) async {
182
- print ("Recent context: ${await value ?.validate () ?? "No Context Found" }" );
183
- })
184
- },
174
+ ElevatedButton (
175
+ onPressed: () async {
176
+ final context =
177
+ await _contextSdkPlugin.recentContext ("my_flow" );
178
+ if (context != null ) {
179
+ print ("Recent context: ${await context .validate ()}" );
180
+ } else {
181
+ print ("No recent context found" );
182
+ }
183
+ },
185
184
child: const Text ('Recent Context' )),
186
185
],
187
186
)),
0 commit comments