LCOV - code coverage report
Current view: top level - src/style - transition_container.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 31 33 93.9 %
Date: 2020-02-15 12:36:36 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/cupertino.dart';
       2             : import 'package:flutter/material.dart';
       3             : 
       4             : import 'transition_container_builder.dart';
       5             : 
       6             : /// Add controller with provided transition api, such as [SlideTransition], [ScaleTransition]
       7             : class TransitionContainer extends StatefulWidget {
       8             :   final TransitionContainerBuilder builder;
       9             :   final Duration duration;
      10             :   final bool disableAnimateWhenUpdate;
      11             : 
      12           0 :   TransitionContainer(
      13             :       {this.builder, this.duration, this.disableAnimateWhenUpdate})
      14           0 :       : assert(builder != null);
      15             : 
      16           1 :   TransitionContainer.scale(
      17             :       {Widget child, Curve curve, this.duration, this.disableAnimateWhenUpdate})
      18           1 :       : builder = ScaleBuilder(curve: curve, child: child);
      19             : 
      20           1 :   TransitionContainer.slide({
      21             :     Widget child,
      22             :     Curve curve,
      23             :     this.duration,
      24             :     bool reverse = false,
      25             :     this.disableAnimateWhenUpdate,
      26           1 :   }) : builder = SlideBuilder(curve: curve, child: child, reverse: reverse);
      27             : 
      28           1 :   TransitionContainer.flip({
      29             :     Widget topChild,
      30             :     Widget bottomChild,
      31             :     Curve curve,
      32             :     double height,
      33             :     this.duration,
      34             :     this.disableAnimateWhenUpdate,
      35           1 :   }) : builder = FlipBuilder(
      36             :           height,
      37             :           curve: curve,
      38             :           topChild: topChild,
      39             :           bottomChild: bottomChild,
      40             :         );
      41             : 
      42           1 :   @override
      43             :   _State createState() {
      44           1 :     return _State();
      45             :   }
      46             : }
      47             : 
      48             : class _State extends State<TransitionContainer> with TickerProviderStateMixin {
      49             :   AnimationController animationController;
      50             :   Animation animation;
      51             : 
      52           1 :   @override
      53             :   void initState() {
      54           1 :     super.initState();
      55           1 :     _setAnimation();
      56             :   }
      57             : 
      58           1 :   void _setAnimation() {
      59           2 :     animationController = AnimationController(
      60             :       vsync: this,
      61           3 :       duration: widget.duration ?? Duration(milliseconds: 150),
      62           4 :     )..addListener(() => setState(() {}));
      63           2 :     animationController.forward();
      64           5 :     animation = widget.builder.animation(animationController);
      65             :   }
      66             : 
      67           1 :   @override
      68             :   void didUpdateWidget(TransitionContainer oldWidget) {
      69           1 :     super.didUpdateWidget(oldWidget);
      70           6 :     if (oldWidget.builder.runtimeType != widget.builder.runtimeType) {
      71           2 :       animationController?.dispose();
      72           1 :       _setAnimation();
      73             :     } else {
      74           4 :       debugPrint('update transition container ${toString()}');
      75           3 :       if (widget.disableAnimateWhenUpdate == true) {
      76             :         return;
      77             :       }
      78           2 :       animationController?.reset();
      79           2 :       animationController?.forward();
      80             :     }
      81             :   }
      82             : 
      83           1 :   @override
      84             :   void dispose() {
      85           2 :     animationController?.dispose();
      86           1 :     super.dispose();
      87             :   }
      88             : 
      89           1 :   @override
      90             :   Widget build(BuildContext context) {
      91           4 :     return widget.builder.build(animation);
      92             :   }
      93             : }

Generated by: LCOV version 1.14