platformPatternItemFromPatternItem function

  1. @visibleForTesting
PlatformPatternItem platformPatternItemFromPatternItem(
  1. PatternItem item
)

Converts a PatternItem to Pigeon's PlatformPatternItem for PlatformPolyline pattern member.

Implementation

@visibleForTesting
PlatformPatternItem platformPatternItemFromPatternItem(PatternItem item) {
  switch (item.type) {
    case PatternItemType.dot:
      return PlatformPatternItem(type: PlatformPatternItemType.dot);
    case PatternItemType.dash:
      final double length = (item as VariableLengthPatternItem).length;
      return PlatformPatternItem(
        type: PlatformPatternItemType.dash,
        length: length,
      );
    case PatternItemType.gap:
      final double length = (item as VariableLengthPatternItem).length;
      return PlatformPatternItem(
        type: PlatformPatternItemType.gap,
        length: length,
      );
  }

  // The enum comes from a different package, which could get a new value at
  // any time, so provide a fallback that ensures this won't break when used
  // with a version that contains new values. This is deliberately outside
  // the switch rather than a `default` so that the linter will flag the
  // switch as needing an update.
  // ignore: dead_code
  return PlatformPatternItem(type: PlatformPatternItemType.dot);
}