LCOV - code coverage report
Current view: top level - lib/src/effects - rotate_effect.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 15 15 100.0 %
Date: 2021-08-10 15:50:53 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:ui';
       2             : 
       3             : import 'package:flutter/animation.dart';
       4             : 
       5             : import '../../components.dart';
       6             : import 'effects.dart';
       7             : 
       8             : class RotateEffect extends SimplePositionComponentEffect {
       9             :   double angle;
      10             :   late double _startAngle;
      11             :   late double _delta;
      12             : 
      13             :   /// Duration or speed needs to be defined
      14           3 :   RotateEffect({
      15             :     required this.angle, // As many radians as you want to rotate
      16             :     double? duration, // How long it should take for completion
      17             :     double? speed, // The speed of rotation in radians/s
      18             :     Curve? curve,
      19             :     bool isInfinite = false,
      20             :     bool isAlternating = false,
      21             :     bool isRelative = false,
      22             :     VoidCallback? onComplete,
      23             :   })  : assert(
      24           3 :           (duration != null) ^ (speed != null),
      25             :           'Either speed or duration necessary',
      26             :         ),
      27           3 :         super(
      28             :           isInfinite,
      29             :           isAlternating,
      30             :           duration: duration,
      31             :           speed: speed,
      32             :           curve: curve,
      33             :           isRelative: isRelative,
      34             :           modifiesAngle: true,
      35             :           onComplete: onComplete,
      36             :         );
      37             : 
      38           3 :   @override
      39             :   void initialize(PositionComponent component) {
      40           3 :     super.initialize(component);
      41           6 :     _startAngle = component.angle;
      42          16 :     _delta = isRelative ? angle : angle - _startAngle;
      43           3 :     if (!isAlternating) {
      44          12 :       endAngle = _startAngle + _delta;
      45             :     }
      46          15 :     speed ??= _delta.abs() / duration!;
      47           3 :     duration ??= _delta.abs() / speed!;
      48          15 :     peakTime = isAlternating ? duration! / 2 : duration!;
      49             :   }
      50             : 
      51           3 :   @override
      52             :   void update(double dt) {
      53           3 :     super.update(dt);
      54          21 :     component?.angle = _startAngle + _delta * curveProgress;
      55             :   }
      56             : }

Generated by: LCOV version 1.15