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

optimizely / optimizely-flutter-sdk / 20140947045

11 Dec 2025 04:58PM UTC coverage: 86.845% (+1.4%) from 85.419%
20140947045

Pull #92

github

web-flow
Merge c6705a306 into 725ec50d6
Pull Request #92: [FSSDK-12086] chore: add nested object support into event meta for Swift

23 of 24 new or added lines in 1 file covered. (95.83%)

680 of 783 relevant lines covered (86.85%)

1.42 hits per line

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

97.44
/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) {
2✔
37
    if (map.isEmpty) {
2✔
38
      return map;
39
    }
40

41
    // Send type along with value so typecasting is easily possible (only for iOS)
42
    Map<String, dynamic> typedMap = {};
2✔
43
    // Only keep primitive values
44
    Map<String, dynamic> primitiveMap = {};
2✔
45
    for (MapEntry e in map.entries) {
4✔
46
      dynamic processedValue = _processValue(e.value);
4✔
47
      if (processedValue != null) {
48
        primitiveMap[e.key] = e.value;
6✔
49
        typedMap[e.key] = processedValue;
4✔
50
      }
51
    }
52

53
    if (Platform.isIOS) {
2✔
54
      return typedMap;
55
    }
56
    return primitiveMap;
57
  }
58

59
  /// Recursively processes values to add type information for iOS
60
  static dynamic _processValue(dynamic value) {
2✔
61
    if (value is String) {
2✔
62
      return {
1✔
63
        Constants.value: value,
64
        Constants.type: Constants.stringType
65
      };
66
    }
67
    if (value is double) {
2✔
68
      return {
1✔
69
        Constants.value: value,
70
        Constants.type: Constants.doubleType
71
      };
72
    }
73
    if (value is int) {
2✔
74
      return {
2✔
75
        Constants.value: value,
76
        Constants.type: Constants.intType
77
      };
78
    }
79
    if (value is bool) {
1✔
80
      return {
1✔
81
        Constants.value: value,
82
        Constants.type: Constants.boolType
83
      };
84
    }
85
    if (value is Map) {
1✔
86
      // Handle nested maps
87
      Map<String, dynamic> nestedMap = {};
1✔
88
      (value as Map).forEach((k, v) {
2✔
89
        dynamic processedValue = _processValue(v);
1✔
90
        if (processedValue != null) {
91
          nestedMap[k.toString()] = processedValue;
2✔
92
        }
93
      });
94
      return {
1✔
95
        Constants.value: nestedMap,
96
        Constants.type: Constants.mapType
97
      };
98
    }
99
    if (value is List) {
1✔
100
      // Handle arrays
101
      List<dynamic> nestedList = [];
1✔
102
      for (var item in value) {
2✔
103
        dynamic processedValue = _processValue(item);
1✔
104
        if (processedValue != null) {
105
          nestedList.add(processedValue);
1✔
106
        }
107
      }
108
      return {
1✔
109
        Constants.value: nestedList,
110
        Constants.type: Constants.listType
111
      };
112
    }
113
    // ignore: avoid_print
NEW
114
    print('Unsupported value type: ${value.runtimeType}');
×
115
    return null;
116
  }
117

118
  static List<String> convertDecideOptions(
1✔
119
      Set<OptimizelyDecideOption> options) {
120
    return options.map((option) => Utils.decideOptions[option]!).toList();
5✔
121
  }
122

123
  static List<String> convertSegmentOptions(
1✔
124
      Set<OptimizelySegmentOption> options) {
125
    return options.map((option) => Utils.segmentOptions[option]!).toList();
5✔
126
  }
127

128
  static String convertLogLevel(OptimizelyLogLevel logLevel) {
1✔
129
    // OptimizelyLogLevel.error -> "error"
130
    // OptimizelyLogLevel.debug -> "debug"
131
    return logLevel.toString().split('.').last;  
3✔
132
  }
133

134
}
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

© 2026 Coveralls, Inc