Skip to content

Commit f342028

Browse files
committed
chore: Clarify Example code
1 parent adb3ba6 commit f342028

File tree

2 files changed

+38
-39
lines changed

2 files changed

+38
-39
lines changed

example/lib/main.dart

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,8 @@ class _MyAppState extends State<MyApp> {
2929
"ddf1949adb3751a25c71cb106b4201eaba9960cbc57e814ffd97ce7d381b0e24c07955a4cdd612f90854198ea600bc15939c182f72308159974b88d5107fe310")
3030
.then((value) => {print("Setup result: $value")});
3131

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});
3834
}
3935

4036
// Platform messages are asynchronous, so we initialize in an async method.
@@ -80,7 +76,7 @@ class _MyAppState extends State<MyApp> {
8076
})
8177
},
8278
child: const Text('Track Event')),
83-
ElevatedButton(
79+
ElevatedButton(
8480
onPressed: () => {
8581
_contextSdkPlugin.trackPageView("my-page", {
8682
'string': 'string',
@@ -90,7 +86,7 @@ class _MyAppState extends State<MyApp> {
9086
})
9187
},
9288
child: const Text('Track Page View')),
93-
ElevatedButton(
89+
ElevatedButton(
9490
onPressed: () => {
9591
_contextSdkPlugin.trackUserAction("my-action", {
9692
'string': 'string',
@@ -100,9 +96,9 @@ class _MyAppState extends State<MyApp> {
10096
})
10197
},
10298
child: const Text('Track User Action')),
103-
ElevatedButton(
99+
ElevatedButton(
104100
onPressed: () async => {
105-
_contextSdkPlugin.calibrate("my_flow", null, {
101+
_contextSdkPlugin.calibrate("my_flow", null, {
106102
'string': 'string',
107103
'int': 14,
108104
'bool': true,
@@ -119,9 +115,9 @@ class _MyAppState extends State<MyApp> {
119115
})
120116
},
121117
child: const Text('Calibrate')),
122-
ElevatedButton(
118+
ElevatedButton(
123119
onPressed: () async => {
124-
_contextSdkPlugin.optimize("my_flow", null, {
120+
_contextSdkPlugin.optimize("my_flow", null, {
125121
'string': 'string',
126122
'int': 14,
127123
'bool': true,
@@ -138,9 +134,9 @@ class _MyAppState extends State<MyApp> {
138134
})
139135
},
140136
child: const Text('Optimize')),
141-
ElevatedButton(
137+
ElevatedButton(
142138
onPressed: () async => {
143-
_contextSdkPlugin.fetchContext("my_flow", 3, {
139+
_contextSdkPlugin.fetchContext("my_flow", 3, {
144140
'string': 'string',
145141
'int': 14,
146142
'bool': true,
@@ -157,31 +153,34 @@ class _MyAppState extends State<MyApp> {
157153
})
158154
},
159155
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+
},
178173
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+
},
185184
child: const Text('Recent Context')),
186185
],
187186
)),

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ packages:
4747
path: ".."
4848
relative: true
4949
source: path
50-
version: "0.0.1"
50+
version: "1.0.0"
5151
cupertino_icons:
5252
dependency: "direct main"
5353
description:

0 commit comments

Comments
 (0)