RTPropertyString.fromString constructor

RTPropertyString.fromString(
  1. String? propertyString, {
  2. String? delimiter,
  3. String? splitDelimiter,
})

Implementation

factory RTPropertyString.fromString(
  String? propertyString, {
  String? delimiter,
  String? splitDelimiter,
}) {
  if (propertyString == null) return RTPropertyString(items: []);

  return RTPropertyString(
    items: propertyString.split(delimiter ?? defaultDelimiter).map((e) {
      try {
        return RTPropertyStringItem(
          key: e.split(splitDelimiter ?? defaultSplitDelimiter)[0],
          value: e.split(splitDelimiter ?? defaultSplitDelimiter)[1],
        );
      } catch (error) {
        return RTPropertyStringItem(
          key: e,
          value: '',
        );
      }
    }).toList(),
  );
}