• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

optimizely / optimizely-flutter-sdk / 15443958305

04 Jun 2025 01:43PM CUT coverage: 84.952%. Remained the same
15443958305

Pull #81

github

web-flow
Merge be2be8dc7 into 4b3c53c27
Pull Request #81: [FSSDK-11453] chore: prepare for release 3.0.1

621 of 731 relevant lines covered (84.95%)

1.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.52
/lib/src/utils/utils.dart
1
/// **************************************************************************
2
/// Copyright 2022, Optimizely, Inc. and contributors                        *
3
///                                                                          *
4
/// Licensed under the Apache License, Version 2.0 (the "License");          *
5
/// you may not use this file except in compliance with the License.         *
6
/// You may obtain a copy of the License at                                  *
7
///                                                                          *
8
///    http://www.apache.org/licenses/LICENSE-2.0                            *
9
///                                                                          *
10
/// Unless required by applicable law or agreed to in writing, software      *
11
/// distributed under the License is distributed on an "AS IS" BASIS,        *
12
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13
/// See the License for the specific language governing permissions and      *
14
/// limitations under the License.                                           *
15
///**************************************************************************/
16

17
import 'dart:io' show Platform;
18
import 'package:optimizely_flutter_sdk/src/user_context/optimizely_user_context.dart';
19
import 'package:optimizely_flutter_sdk/src/utils/constants.dart';
20
import 'package:optimizely_flutter_sdk/src/data_objects/log_level.dart';
21

22
class Utils {
23
  static Map<OptimizelyDecideOption, String> decideOptions = {
3✔
24
    OptimizelyDecideOption.disableDecisionEvent: "disableDecisionEvent",
25
    OptimizelyDecideOption.enabledFlagsOnly: "enabledFlagsOnly",
26
    OptimizelyDecideOption.ignoreUserProfileService: "ignoreUserProfileService",
27
    OptimizelyDecideOption.includeReasons: "includeReasons",
28
    OptimizelyDecideOption.excludeVariables: "excludeVariables",
29
  };
30

31
  static Map<OptimizelySegmentOption, String> segmentOptions = {
3✔
32
    OptimizelySegmentOption.ignoreCache: "ignoreCache",
33
    OptimizelySegmentOption.resetCache: "resetCache",
34
  };
35

36
  static Map<String, dynamic> convertToTypedMap(Map<String, dynamic> map) {
1✔
37
    if (map.isEmpty) {
1✔
38
      return map;
39
    }
40

41
    // Send type along with value so typecasting is easily possible (only for iOS)
42
    Map<String, dynamic> typedMap = {};
1✔
43
    // Only keep primitive values
44
    Map<String, dynamic> primitiveMap = {};
1✔
45
    for (MapEntry e in map.entries) {
2✔
46
      if (e.value is String) {
2✔
47
        primitiveMap[e.key] = e.value;
×
48
        typedMap[e.key] = {
×
49
          Constants.value: e.value,
×
50
          Constants.type: Constants.stringType
51
        };
52
        continue;
53
      }
54
      if (e.value is double) {
2✔
55
        primitiveMap[e.key] = e.value;
×
56
        typedMap[e.key] = {
×
57
          Constants.value: e.value,
×
58
          Constants.type: Constants.doubleType
59
        };
60
        continue;
61
      }
62
      if (e.value is int) {
2✔
63
        primitiveMap[e.key] = e.value;
3✔
64
        typedMap[e.key] = {
3✔
65
          Constants.value: e.value,
1✔
66
          Constants.type: Constants.intType
67
        };
68
        continue;
69
      }
70
      if (e.value is bool) {
×
71
        primitiveMap[e.key] = e.value;
×
72
        typedMap[e.key] = {
×
73
          Constants.value: e.value,
×
74
          Constants.type: Constants.boolType
75
        };
76
        continue;
77
      }
78
      // ignore: avoid_print
79
      print('Unsupported value type for key: ${e.key}.');
×
80
    }
81

82
    if (Platform.isIOS) {
1✔
83
      return typedMap;
84
    }
85
    return primitiveMap;
86
  }
87

88
  static List<String> convertDecideOptions(
1✔
89
      Set<OptimizelyDecideOption> options) {
90
    return options.map((option) => Utils.decideOptions[option]!).toList();
5✔
91
  }
92

93
  static List<String> convertSegmentOptions(
1✔
94
      Set<OptimizelySegmentOption> options) {
95
    return options.map((option) => Utils.segmentOptions[option]!).toList();
5✔
96
  }
97

98
  static String convertLogLevel(OptimizelyLogLevel logLevel) {
1✔
99
    // OptimizelyLogLevel.error -> "error"
100
    // OptimizelyLogLevel.debug -> "debug"
101
    return logLevel.toString().split('.').last;  
3✔
102
  }
103

104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc