LCOV - code coverage report
Current view: top level - src/style - transition_container_builder.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 42 42 100.0 %
Date: 2020-02-24 15:58:08 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:math';
       2             : 
       3             : import 'package:flutter/animation.dart';
       4             : import 'package:flutter/cupertino.dart';
       5             : 
       6             : import 'transition_container.dart';
       7             : 
       8             : /// Interface to provide a transition, work with [TransitionContainer].
       9             : abstract class TransitionContainerBuilder {
      10             :   /// Curve for animation.
      11             :   final Curve curve;
      12             : 
      13           1 :   TransitionContainerBuilder(this.curve);
      14             : 
      15             :   /// Animation used for widget.
      16             :   Animation animation(AnimationController controller);
      17             : 
      18             :   /// Return animated widget with provided animation.
      19             :   Widget build(Animation animation);
      20             : }
      21             : 
      22             : /// Scale transition builder.
      23             : class ScaleBuilder extends TransitionContainerBuilder {
      24             :   Widget child;
      25             : 
      26           1 :   @override
      27             :   Animation animation(AnimationController controller) {
      28           2 :     return CurvedAnimation(parent: controller, curve: curve);
      29             :   }
      30             : 
      31           1 :   @override
      32             :   Widget build(Animation animation) {
      33           2 :     return ScaleTransition(scale: animation, child: child);
      34             :   }
      35             : 
      36           2 :   ScaleBuilder({Curve curve, this.child}) : super(curve);
      37             : }
      38             : 
      39             : /// Slide transition builder.
      40             : class SlideBuilder extends TransitionContainerBuilder {
      41             :   Widget child;
      42             :   final bool reverse;
      43             : 
      44           2 :   SlideBuilder({Curve curve, this.child, this.reverse}) : super(curve);
      45             : 
      46           1 :   @override
      47             :   Widget build(Animation animation) {
      48           2 :     return SlideTransition(position: animation, child: child);
      49             :   }
      50             : 
      51           1 :   @override
      52             :   Animation animation(AnimationController controller) {
      53           1 :     return Tween<Offset>(
      54           1 :       begin: reverse ? Offset.zero : const Offset(0.0, 2.0),
      55           1 :       end: reverse ? const Offset(0.0, 2.0) : Offset.zero,
      56           3 :     ).animate(CurvedAnimation(parent: controller, curve: curve));
      57             :   }
      58             : }
      59             : 
      60             : /// This flip animation is origin from [https://github.com/deven98/flip_box_bar/blob/master/lib/src/flip_box.dart]
      61             : /// UX => ![](https://cdn.dribbble.com/users/1094383/screenshots/4811135/800_5.gif).
      62             : class FlipBuilder extends TransitionContainerBuilder {
      63             :   final Widget topChild;
      64             :   final Widget bottomChild;
      65             :   final double height;
      66             : 
      67           1 :   FlipBuilder(this.height, {Curve curve, this.topChild, this.bottomChild})
      68           1 :       : super(curve);
      69             : 
      70           1 :   @override
      71             :   Animation animation(AnimationController controller) {
      72           3 :     return Tween(begin: 0.0, end: pi / 2).animate(
      73           2 :       CurvedAnimation(parent: controller, curve: curve),
      74             :     );
      75             :   }
      76             : 
      77           1 :   @override
      78             :   Widget build(Animation animation) {
      79           1 :     return Container(
      80           1 :       child: Stack(
      81           1 :         children: <Widget>[
      82           1 :           Transform(
      83             :             alignment: Alignment.bottomCenter,
      84           1 :             transform: Matrix4.identity()
      85           1 :               ..setEntry(3, 2, 0.001)
      86           6 :               ..translate(0.0, (cos(animation.value) * (height / 2)),
      87           5 :                   ((height / 2) * sin(animation.value)))
      88           5 :               ..rotateX(-(pi / 2) + animation.value),
      89           1 :             child: Container(
      90           2 :               child: Center(child: bottomChild),
      91             :             ),
      92             :           ),
      93           4 :           animation.value < (85 * pi / 180)
      94           1 :               ? Transform(
      95             :                   alignment: Alignment.bottomCenter,
      96           1 :                   transform: Matrix4.identity()
      97           1 :                     ..setEntry(3, 2, 0.001)
      98           1 :                     ..translate(
      99             :                       0.0,
     100           6 :                       -(height / 2) * sin(animation.value),
     101           5 :                       ((height / 2) * cos(animation.value)),
     102             :                     )
     103           2 :                     ..rotateX(animation.value),
     104           1 :                   child: Container(
     105             :                     alignment: Alignment.bottomCenter,
     106           2 :                     child: Center(child: topChild),
     107             :                   ),
     108             :                 )
     109           1 :               : Container(),
     110             :         ],
     111             :       ),
     112             :     );
     113             :   }
     114             : }

Generated by: LCOV version 1.14