toJson static method

Map<String, dynamic> toJson(
  1. Animation animation
)

Implementation

static Map<String, dynamic> toJson(Animation animation) {
  final json = <String, dynamic>{
    'type': animation.type.toString().split('.').last,
    'start': animation.start,
    'end': animation.end,
  };

  switch (animation.type) {
    case AnimationType.translate:
      final translate = animation as TranslateAnimation;
      json['x'] = translate.x;
      json['y'] = translate.y;
      break;
    case AnimationType.rotate:
      final rotate = animation as RotateAnimation;
      json['angle'] = rotate.angle;
      json['pivotX'] = rotate.pivotX;
      json['pivotY'] = rotate.pivotY;
      break;
    case AnimationType.scale:
      final scale = animation as ScaleAnimation;
      json['scaleX'] = scale.scaleX;
      json['scaleY'] = scale.scaleY;
      json['pivotX'] = scale.pivotX;
      json['pivotY'] = scale.pivotY;
      break;
    case AnimationType.alpha:
      final alpha = animation as AlphaAnimation;
      json['alpha'] = alpha.alpha;
      break;
    case AnimationType.sound:
      // SoundAnimation не имеет дополнительных полей
      break;
  }

  return json;
}