Skip to content

Commit 5fef979

Browse files
committed
add decode fix
1 parent 8097836 commit 5fef979

File tree

8 files changed

+24
-13
lines changed

8 files changed

+24
-13
lines changed

example/lib/Providers/fs_data.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
66

77
class FSData extends ChangeNotifier {
88
// Apikey
9-
String _apiKey = "apiKey"; //
9+
String _apiKey = "DxAcxlnRB9yFBZYtLDue1q01dcXZCw6aM49CQB23"; //
1010
// EnvId
1111
String _envId = "bkk9glocmjcg0vtmdlng"; //
1212
// Mode
@@ -70,7 +70,8 @@ class UserData extends ChangeNotifier {
7070
Map<String, Object> context = {
7171
"testing_tracking_manager": true,
7272
"isQA": true,
73-
"fs_is_vip": true
73+
"fs_is_vip": true,
74+
"condition1": "spécial"
7475
};
7576
bool _hasConsented = true;
7677
bool _isAuthenticated = false;

example/lib/widgets/Modifications.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@ class _ModificationsState extends State<Modifications> {
5555
defaultValue = double.parse(defaultValueFlagController.text);
5656
}
5757
if (flagType == "array" || flagType == "object") {
58-
defaultValue = jsonDecode(defaultValueFlagController.text);
58+
try {
59+
defaultValue = jsonDecode(defaultValueFlagController.text);
60+
} catch (e) {
61+
defaultValue = jsonDecode("{}");
62+
}
5963
}
6064

6165
myFlag = currentVisitor?.getFlag(keyFlagController.text);
6266

6367
var ret = myFlag?.value(defaultValue);
68+
print("The Flag value is $ret \n");
6469

6570
setState(() {
6671
valueForFlag = ret.toString();

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ packages:
103103
path: ".."
104104
relative: true
105105
source: path
106-
version: "4.1.0"
106+
version: "4.1.1-beta"
107107
flutter:
108108
dependency: "direct main"
109109
description: flutter

lib/decision/api_manager.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ class ApiManager extends DecisionManager {
4141
Flagship.sharedInstance().getConfiguration()?.timeout ?? TIMEOUT);
4242
switch (response.statusCode) {
4343
case 200:
44-
Flagship.logger(Level.ALL, response.body, isJsonString: true);
45-
return Campaigns.fromJson(json.decode(response.body));
44+
Flagship.logger(Level.ALL, utf8.decode(response.bodyBytes),
45+
isJsonString: true);
46+
return Campaigns.fromJson(json.decode(utf8.decode(response.bodyBytes)));
4647
default:
4748
Flagship.logger(
4849
Level.ALL,

lib/decision/bucketing_manager.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class BucketingManager extends DecisionManager {
7474
Flagship.sharedInstance().getConfiguration()?.timeout ?? TIMEOUT);
7575
switch (response.statusCode) {
7676
case 200:
77-
Flagship.logger(Level.ALL, response.body, isJsonString: true);
77+
Flagship.logger(Level.ALL, utf8.decode(response.bodyBytes),
78+
isJsonString: true);
7879
String? lastModified = response.headers["last-modified"];
7980
if (lastModified != null) {
8081
prefs.setString(
@@ -83,12 +84,13 @@ class BucketingManager extends DecisionManager {
8384
lastModified);
8485
}
8586
// Save response body
86-
_saveFile(response.body);
87+
_saveFile(utf8.decode(response.bodyBytes));
8788
// Report TR
8889
DataUsageTracking.sharedInstance().processTroubleShootingHttp(
8990
CriticalPoints.SDK_BUCKETING_FILE.name, response);
9091
// Update sdk status
91-
return Bucketing.fromJson(json.decode(response.body));
92+
return Bucketing.fromJson(json.decode(utf8.decode(response.bodyBytes)));
93+
9294
case 304:
9395
Flagship.logger(Level.ALL,
9496
"The bucketing script is not modified since last download");

test/flag_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ void main() async {
327327
// is not empty
328328
expect(fCollect.isEmpty, false);
329329
// Count == 11
330-
expect(fCollect.count, 11);
330+
expect(fCollect.count, 12);
331331

332332
var collectResult = fCollect.filter((key, flag) {
333333
return (key == "key_B");

test/test_resources/decisionApi.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"key_B":3.14,
3838
"key_C": 2,
3939
"key_D":true,
40-
"keyNull":null
40+
"keyNull":null,
41+
"specialChar":"Ceci est un exemple avec des caractères spéciaux : é, à, ü, œ, ñ, ç…"
4142
}
4243
},
4344
"reference": true

test/test_tools.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import 'dart:io';
2+
import 'dart:convert';
23
import 'package:flutter_test/flutter_test.dart';
34
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
45

56
class ToolsTest {
67
/// Read the mock response
78
static Future<String?> readFile(String path) async {
89
final file = new File(testPath(path));
9-
final jsonString = await file.readAsString();
10-
return jsonString;
10+
final jsonBytes = await file.readAsBytes();
11+
return latin1.decode(jsonBytes);
1112
}
1213

1314
/// From : https://github.com/terryx/flutter-muscle/blob/master/github_provider/test/utils/test_path.dart

0 commit comments

Comments
 (0)