Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SizeTransition widget

I want to use SizeTransition widget for just an image not for page. It will be my loading page and while loading the application app symbol will be displayed with a size transition.

https://docs.flutter.io/flutter/widgets/SizeTransition-class.html

I want my logo with this effect in the link. However there is not enough source for me to learn about that widget. Can you please give me an example? I tried something like this but it;s not working.

class _AnimTestState extends State<AnimTest>
    with SingleTickerProviderStateMixin {
  AnimationController controller;
  @override
  void initState() {
    super.initState();
    controller = AnimationController(vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SizeTransition(
        child: Image.asset('assets/images/appLogo.png'),
        sizeFactor: CurvedAnimation(
          curve: Curves.fastOutSlowIn,
          parent: controller,
        ),
      ),
    );
  }
}
like image 915
niwufujol Avatar asked Oct 16 '25 07:10

niwufujol


1 Answers

class _AnimTestState extends State<HomePage> with SingleTickerProviderStateMixin {
  AnimationController controller;

  @override
  void initState() {
    super.initState();
    controller = AnimationController(
      vsync: this,
      duration: Duration(milliseconds: 400),
    )..repeat(reverse: true); // automatically animation will be started
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SizeTransition(
        child: Image.asset('assets/images/appLogo.png'),
        sizeFactor: CurvedAnimation(
          curve: Curves.fastOutSlowIn,
          parent: controller,
        ),
      ),
    );
  }
}

You can also use _controller.forward() or _controller.reverse() in a button press if you don't want it to run automatically like I did.

like image 151
CopsOnRoad Avatar answered Oct 18 '25 01:10

CopsOnRoad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!