flutter widget animation code example

Example 1: Animation Flutter

class _WelcomeScreenState extends State
  with SingleTickerProviderStateMixin {
  AnimationController controller;
  Animation animation;

  @override
  void initState() {
  super.initState();
  controller = AnimationController(
  duration: Duration(seconds: 1),
  vsync: this,
  );

  animation = ColorTween(begin: Colors.blueGrey, end: Colors.white)
      .animate(controller);

  controller.forward();

  controller.addListener(() {
  setState(() {});
  print(animation.value);
  });
  }

Example 2: stateless widget flutter

class GreenFrog extends StatelessWidget {
  const GreenFrog({ Key key }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(color: const Color(0xFF2DBD3A));
  }
}

Example 3: flutter show widget with animation

//Check this out  
https://www.smashingmagazine.com/2019/10/animation-apps-flutter/

Example 4: flutter inhereted widget

class MyInherited extends InheritedWidget {
  const MyInherited({
    Key key,
    @required Widget child,
  }) : super(key: key, child: child);


  static MyInherited of(BuildContext context) {
    return context.dependOnInheritedWidgetOfExactType();
  }

  //if you have properties, it should look something like:
  // bool updateShouldNotify(MyInherited old) => old.prop !== new.prop;
  
  //if you don't: 
  @override
  bool updateShouldNotify(MyInherited old) => false;
  
}

Tags:

Misc Example