buildLayerComponent function

String buildLayerComponent(
  1. String sourceParamKey,
  2. Source source, {
  3. BaseLayerPosition? position,
  4. BlendMode? blendMode,
  5. Timeline? timeline,
  6. List<Param>? extras,
})

Implementation

String buildLayerComponent(String sourceParamKey, Source source,
    {BaseLayerPosition? position,
    BlendMode? blendMode,
    Timeline? timeline,
    List<Param>? extras}) {
  List<Param> newList = <Param>[];
  newList.addAll(source.extraComponents());
  newList.add(Param(sourceParamKey, source.toString()));
  var sourceComponent = toComponentString(newList);

  // The extra params, alongside position and timeline-position, plus fl_layer_apply - all go in the last component:
  var splited = sourceComponent.split(',');
  splited.sort((a, b) => a.toString().compareTo(b.toString()));
  var sorted = splited.join(',');
  List<Param> lastComponent = <Param>[];
  if (extras != null) {
    lastComponent.addAll(extras);
  }
  lastComponent.add(Param('fl', 'layer_apply'));
  if (position != null) {
    lastComponent.addAll(position.asParams());
  }
  if (timeline != null) {
    if (timeline.getStartOffset() != null) {
      lastComponent.add(Param("so", timeline.getStartOffset()));
    }
    if (timeline.getDuration() != null) {
      lastComponent.add(Param("eo", timeline.getEndOffset()));
    }
    if (timeline.getEndOffset() != null) {
      lastComponent.add(Param("du", timeline.getDuration()));
    }
  }
  if (blendMode != null) {
    lastComponent.add(Param('e', blendMode));
  }
  var lastComponentString = toComponentString(lastComponent);
  return sorted.joinWithValues(
      [source.transformationObject, lastComponentString],
      separator: defaultComponentSeparator,
      actionSeparator: defaultComponentSeparator);
}