LCOV - code coverage report
Current view: top level - lib/src/effects - size_effect.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 14 15 93.3 %
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 '../extensions/vector2.dart';
       7             : import 'effects.dart';
       8             : 
       9             : class SizeEffect extends SimplePositionComponentEffect {
      10             :   Vector2 size;
      11             :   late Vector2 _startSize;
      12             :   late Vector2 _delta;
      13             : 
      14             :   /// Duration or speed needs to be defined
      15           3 :   SizeEffect({
      16             :     required this.size,
      17             :     double? duration, // How long it should take for completion
      18             :     double? speed, // The speed of the scaling in pixels per second
      19             :     Curve? curve,
      20             :     bool isInfinite = false,
      21             :     bool isAlternating = false,
      22             :     bool isRelative = false,
      23             :     VoidCallback? onComplete,
      24             :   })  : assert(
      25           0 :           duration != null || speed != null,
      26             :           'Either speed or duration necessary',
      27             :         ),
      28           3 :         super(
      29             :           isInfinite,
      30             :           isAlternating,
      31             :           duration: duration,
      32             :           speed: speed,
      33             :           curve: curve,
      34             :           isRelative: isRelative,
      35             :           modifiesSize: true,
      36             :           onComplete: onComplete,
      37             :         );
      38             : 
      39           3 :   @override
      40             :   void initialize(PositionComponent component) {
      41           3 :     super.initialize(component);
      42           9 :     _startSize = component.size.clone();
      43          15 :     _delta = isRelative ? size : size - _startSize;
      44           3 :     if (!isAlternating) {
      45          12 :       endSize = _startSize + _delta;
      46             :     }
      47          15 :     speed ??= _delta.length / duration!;
      48           3 :     duration ??= _delta.length / speed!;
      49          15 :     peakTime = isAlternating ? duration! / 2 : duration!;
      50             :   }
      51             : 
      52           3 :   @override
      53             :   void update(double dt) {
      54           3 :     super.update(dt);
      55          24 :     component?.size.setFrom(_startSize + _delta * curveProgress);
      56             :   }
      57             : }

Generated by: LCOV version 1.15