@@ -3,23 +3,32 @@ import 'dart:async';
3
3
import 'package:confidence_flutter_sdk/confidence_flutter_sdk.dart' ;
4
4
import 'package:flutter/material.dart' ;
5
5
import 'package:flutter/services.dart' ;
6
+ import 'package:flutter_dotenv/flutter_dotenv.dart' ;
6
7
7
8
void main () {
8
- runApp (const MyApp ());
9
+ runApp (MyApp ());
9
10
}
10
11
11
12
class MyApp extends StatefulWidget {
12
- const MyApp ({super .key});
13
+ MyApp ({super .key});
14
+ final Completer <void > _initCompleter = Completer <void >();
15
+
16
+ Future <void > initDone () async {
17
+ return _initCompleter.future;
18
+ }
13
19
14
20
@override
15
- State <MyApp > createState () => _MyAppState ();
21
+ // ignore: no_logic_in_create_state
22
+ State <MyApp > createState () => _MyAppState (_initCompleter);
16
23
}
17
24
18
25
class _MyAppState extends State <MyApp > {
19
26
String _object = 'Unknown' ;
20
27
String _message = 'Unknown' ;
21
- bool _enabled = false ;
22
28
final _confidenceFlutterSdkPlugin = ConfidenceFlutterSdk ();
29
+ final Completer <void > initCompleter;
30
+
31
+ _MyAppState (this .initCompleter);
23
32
24
33
@override
25
34
void initState () {
@@ -30,23 +39,19 @@ class _MyAppState extends State<MyApp> {
30
39
// Platform messages are asynchronous, so we initialize in an async method.
31
40
Future <void > initPlatformState () async {
32
41
String message;
33
- bool enabled;
34
42
String object;
35
43
// Platform messages may fail, so we use a try/catch PlatformException.
36
44
// We also handle the message potentially returning null.
37
45
try {
38
- await _confidenceFlutterSdkPlugin.setup ("API_KEY" );
39
- if (await _confidenceFlutterSdkPlugin.isStorageEmpty ()) {
40
- await _confidenceFlutterSdkPlugin.fetchAndActivate ();
41
- } else {
42
- await _confidenceFlutterSdkPlugin.activateAndFetchAsync ();
43
- }
44
- await _confidenceFlutterSdkPlugin.putContext ("Yo" , "Hello" );
46
+ await dotenv.load (fileName: ".env" );
47
+ await _confidenceFlutterSdkPlugin.setup (dotenv.env["API_KEY" ]! );
48
+ await _confidenceFlutterSdkPlugin.putContext ("targeting_key" , "random" );
49
+ await _confidenceFlutterSdkPlugin.putContext ("user" , < String , dynamic > {"country" : "SE" });
50
+ await _confidenceFlutterSdkPlugin.fetchAndActivate ();
45
51
object =
46
- (await _confidenceFlutterSdkPlugin.getObject ("hawkflag " , < String , dynamic > {})).toString ();
52
+ (await _confidenceFlutterSdkPlugin.getObject ("kotlin-test-flag " , < String , dynamic > {})).toString ();
47
53
message =
48
- (await _confidenceFlutterSdkPlugin.getString ("hawkflag.message" , "default" )).toString ();
49
- enabled = await _confidenceFlutterSdkPlugin.getBool ("hawkflag.enabled" , false );
54
+ (await _confidenceFlutterSdkPlugin.getInt ("kotlin-test-flag.my-integer" , 0 )).toString ();
50
55
final data = {
51
56
'screen' : 'home' ,
52
57
"my_bool" : false ,
@@ -59,7 +64,6 @@ class _MyAppState extends State<MyApp> {
59
64
_confidenceFlutterSdkPlugin.flush ();
60
65
} on PlatformException {
61
66
message = 'Failed to get platform version.' ;
62
- enabled = false ;
63
67
object = 'Failed to get object.' ;
64
68
}
65
69
@@ -69,10 +73,10 @@ class _MyAppState extends State<MyApp> {
69
73
if (! mounted) return ;
70
74
71
75
setState (() {
72
- _enabled = enabled;
73
76
_message = message;
74
77
_object = object;
75
78
});
79
+ initCompleter.complete ();
76
80
}
77
81
78
82
@override
@@ -84,19 +88,17 @@ class _MyAppState extends State<MyApp> {
84
88
),
85
89
body: Center (
86
90
child: ListView .builder (
87
- itemCount: 3 ,
91
+ itemCount: 2 ,
88
92
itemBuilder: (context, index) {
89
93
var title = "" ;
90
94
switch (index) {
91
95
case 0 :
92
- title = 'Message: $ _message \n ' ;
96
+ title = _message;
93
97
case 1 :
94
- title = 'Enabled: $_enabled \n ' ;
95
- case 2 :
96
- title = 'Object: \n $_object \n ' ;
98
+ title = _object;
97
99
}
98
100
return ListTile (
99
- title: Text ('Evaluation -> $title \n ' ),
101
+ title: Text ('$title \n ' ),
100
102
);
101
103
},
102
104
),
0 commit comments