GetFlag.fromMap constructor

GetFlag.fromMap(
  1. Map<String, dynamic> map
)

Factory constructor to create a Flag from a Map

Implementation

factory GetFlag.fromMap(Map<String, dynamic> map) {
  // Safely cast '_isEnabled' to a boolean
  bool isEnabled = map['isEnabled'] is bool ? map['isEnabled'] : false;

  // Safely handle the 'variables' list, ensuring each item is a Map<String, dynamic>
  List<Variable> variables = [];
  if (map['variables'] is List) {
    variables = (map['variables'] as List<dynamic>).map((v) {
      if (v is Map<Object?, Object?>) {
        // Safely convert the map to Map<String, dynamic>
        Map<String, dynamic> map = v.cast<String, dynamic>();
        return Variable.fromMap(map);
      }
      return Variable(); // Or handle invalid case
    }).toList();
  }

  return GetFlag(
    isEnabled: isEnabled,
    variables: variables,
  );
}