3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
5
import 'dart:convert' show utf8;
6
+ import 'dart:js_interop' ;
7
+
6
8
import 'package:firebase_core_web/firebase_core_web_interop.dart' ;
7
9
import 'package:firebase_remote_config_platform_interface/firebase_remote_config_platform_interface.dart' ;
10
+
8
11
import 'firebase_remote_config_interop.dart' as remote_config_interop;
9
12
10
13
/// Given an AppJSImp, return the Remote Config instance.
@@ -55,12 +58,14 @@ class RemoteConfig
55
58
56
59
/// Returns the timestamp of the last *successful* fetch.
57
60
DateTime get fetchTime {
58
- return DateTime .fromMillisecondsSinceEpoch (jsObject.fetchTimeMillis);
61
+ return DateTime .fromMillisecondsSinceEpoch (
62
+ jsObject.fetchTimeMillis.toDartInt,
63
+ );
59
64
}
60
65
61
66
/// The status of the last fetch attempt.
62
67
RemoteConfigFetchStatus get lastFetchStatus {
63
- switch (jsObject.lastFetchStatus) {
68
+ switch (jsObject.lastFetchStatus.toDart ) {
64
69
case 'no-fetch-yet' :
65
70
return RemoteConfigFetchStatus .notFetchedYet;
66
71
case 'success' :
@@ -70,29 +75,33 @@ class RemoteConfig
70
75
case 'throttle' :
71
76
return RemoteConfigFetchStatus .throttle;
72
77
default :
73
- throw UnimplementedError (jsObject.lastFetchStatus);
78
+ throw UnimplementedError (jsObject.lastFetchStatus.toDart );
74
79
}
75
80
}
76
81
77
82
/// Makes the last fetched config available to the getters.
78
83
/// Returns a future which resolves to `true` if the current call activated the fetched configs.
79
84
/// If the fetched configs were already activated, the promise will resolve to `false` .
80
- Future <bool > activate () async =>
81
- handleThenable (remote_config_interop.activate (jsObject));
85
+ Future <bool > activate () async => remote_config_interop
86
+ .activate (jsObject)
87
+ .toDart
88
+ .then ((value) => value! as bool );
82
89
83
90
/// Ensures the last activated config are available to the getters.
84
91
Future <void > ensureInitialized () async =>
85
- handleThenable ( remote_config_interop.ensureInitialized (jsObject)) ;
92
+ remote_config_interop.ensureInitialized (jsObject).toDart ;
86
93
87
94
/// Fetches and caches configuration from the Remote Config service.
88
95
Future <void > fetch () async =>
89
- handleThenable ( remote_config_interop.fetchConfig (jsObject)) ;
96
+ remote_config_interop.fetchConfig (jsObject).toDart ;
90
97
91
98
/// Performs fetch and activate operations, as a convenience.
92
99
/// Returns a promise which resolves to true if the current call activated the fetched configs.
93
100
/// If the fetched configs were already activated, the promise will resolve to false.
94
101
Future <bool > fetchAndActivate () async =>
95
- handleThenable (remote_config_interop.fetchAndActivate (jsObject));
102
+ remote_config_interop.fetchAndActivate (jsObject).toDart.then (
103
+ (value) => value! as bool ,
104
+ );
96
105
97
106
/// Returns all config values.
98
107
Map <String , RemoteConfigValue > getAll () {
@@ -104,23 +113,28 @@ class RemoteConfig
104
113
}
105
114
106
115
RemoteConfigValue getValue (String key) => RemoteConfigValue (
107
- utf8.encode (remote_config_interop.getValue (jsObject, key).asString ()),
108
- getSource (remote_config_interop.getValue (jsObject, key).getSource ()),
116
+ utf8.encode (
117
+ remote_config_interop.getValue (jsObject, key.toJS).asString ().toDart,
118
+ ),
119
+ getSource (
120
+ remote_config_interop.getValue (jsObject, key.toJS).getSource ().toDart,
121
+ ),
109
122
);
110
123
111
124
/// Gets the value for the given key as a boolean.
112
125
/// Convenience method for calling `remoteConfig.getValue(key).asString()` .
113
126
bool getBoolean (String key) =>
114
- remote_config_interop.getBoolean (jsObject, key) ;
127
+ remote_config_interop.getBoolean (jsObject, key.toJS).toDart ;
115
128
116
129
/// Gets the value for the given key as a number.
117
130
/// Convenience method for calling `remoteConfig.getValue(key).asNumber()` .
118
- num getNumber (String key) => remote_config_interop.getNumber (jsObject, key);
131
+ num getNumber (String key) =>
132
+ remote_config_interop.getNumber (jsObject, key.toJS).toDartDouble;
119
133
120
134
/// Gets the value for the given key as a string.
121
135
/// Convenience method for calling `remoteConfig.getValue(key).asString()` .
122
136
String getString (String key) =>
123
- remote_config_interop.getString (jsObject, key) ;
137
+ remote_config_interop.getString (jsObject, key.toJS).toDart ;
124
138
125
139
void setLogLevel (RemoteConfigLogLevel value) {
126
140
remote_config_interop.setLogLevel (
@@ -129,7 +143,8 @@ class RemoteConfig
129
143
RemoteConfigLogLevel .debug: 'debug' ,
130
144
RemoteConfigLogLevel .error: 'error' ,
131
145
RemoteConfigLogLevel .silent: 'silent' ,
132
- }[value]! ,
146
+ }[value]!
147
+ .toJS,
133
148
);
134
149
}
135
150
}
@@ -157,19 +172,19 @@ class RemoteConfigSettings
157
172
/// Defines the maximum age in milliseconds of an entry in the config cache before
158
173
/// it is considered stale. Defaults to twelve hours.
159
174
Duration get minimumFetchInterval =>
160
- Duration (milliseconds: jsObject.minimumFetchIntervalMillis);
175
+ Duration (milliseconds: jsObject.minimumFetchIntervalMillis.toDartInt );
161
176
162
177
set minimumFetchInterval (Duration value) {
163
- jsObject.minimumFetchIntervalMillis = value.inMilliseconds;
178
+ jsObject.minimumFetchIntervalMillis = value.inMilliseconds.toJS ;
164
179
}
165
180
166
181
/// Defines the maximum amount of time to wait for a response when fetching
167
182
/// configuration from the Remote Config server. Defaults to one minute.
168
183
Duration get fetchTimeoutMillis =>
169
- Duration (milliseconds: jsObject.fetchTimeoutMillis);
184
+ Duration (milliseconds: jsObject.fetchTimeoutMillis.toDartInt );
170
185
171
186
set fetchTimeoutMillis (Duration value) {
172
- jsObject.fetchTimeoutMillis = value.inMilliseconds;
187
+ jsObject.fetchTimeoutMillis = value.inMilliseconds.toJS ;
173
188
}
174
189
}
175
190
0 commit comments