spread_widget.dart 1.47 KB
import 'package:flutter/material.dart';
class ScaleAnimatedContentSim extends StatefulWidget {
  final Widget child;
  final bool show;
 
  const ScaleAnimatedContentSim({Key key, this.child, this.show = false})
      : super(key: key);
 
  @override
  ScaleAnimatedContentSimState createState() => ScaleAnimatedContentSimState();
}
 
class ScaleAnimatedContentSimState extends State<ScaleAnimatedContentSim>
    with TickerProviderStateMixin {
  AnimationController animationController;
  Animation<double> animation;
 
  @override
  void initState() {
    animationController = new AnimationController(
      vsync: this,
      duration: new Duration(milliseconds: 600),
    );
 
    // animationSlideUp = new Tween(begin: 0.0,end: 1.0).animate(animationController);
    animation = Tween(begin: 0.0, end: 1.0).animate(animationController);
 
    if (widget.show) {
      animationController.forward();
    }
 
    super.initState();
  }
 
  @override
  void didUpdateWidget(ScaleAnimatedContentSim oldWidget) {
    if (widget != oldWidget) {
      if (widget.show && !oldWidget.show) {
        animationController.forward(from: 0.0);
      } else if (!widget.show) {
        animationController.reverse();
      }
    }
    super.didUpdateWidget(oldWidget);
  }
 
  @override
  Widget build(BuildContext context) {
    return ScaleTransition(
      scale: animation,
      child: widget.child,
    );
  }
 
  @override
  void dispose() {
    animationController.dispose();
    super.dispose();
  }
}