Problems with multiple tween animations in Flutter - Videos Included












2















I have a weird flutter issue with a certain animation I'm trying to create.



I am trying to animate an image onto the screen.
I want it to move on the x-axis, and I want it to slowly fade in as well.



So I figured - Positioned and Opacity, and animate their value with a tween.



Both the Positioned and Opacity widgets work great on their own, but when I combine the two - I get a weird animation, that only starts to draw after a while (about 3 seconds).



I tried printing the animation.value and it seems to be fine, slowly climbing from 0.0 to 1.0 - but the clouds suddenly appear only after like 3 seconds.



I tried separating them to different controllers, thought that maybe somehow that was the culprit, but nope.



TLDR Videos:



Opacity Animation Only



Positioned Animation Only



Both Animations Combined - NOT GOOD



Here's the widget's code:



import 'package:app/weather/widgets/CloudProperties.dart';
import 'package:flutter/widgets.dart';

class WeatherCloudWidget extends StatefulWidget {
final double sunSize;
final CloudProperties properties;

WeatherCloudWidget({Key key, this.properties, this.sunSize})
: super(key: key);

@override
State<StatefulWidget> createState() => _WeatherCloudWidget();
}

class _WeatherCloudWidget extends State<WeatherCloudWidget>
with TickerProviderStateMixin {
AnimationController controller;
AnimationController controller2;

Animation<double> position;
Animation<double> opacity;

@override
initState() {
super.initState();
_startAnimation();
}

@override
Widget build(BuildContext context) {
// screen width and height
final screenWidth = MediaQuery.of(context).size.width;
final screenHeight = MediaQuery.of(context).size.height;

final properties = widget.properties;

var vertical =
screenHeight * 0.5 + (widget.sunSize * properties.verticalOffset * -1);

var horizontal = (screenWidth * 0.5) + (widget.sunSize * position.value);

print(opacity.value);

// both Positioned & Opacity widgets

return Positioned(
left: horizontal,
top: vertical,
child: Opacity(
opacity: opacity.value,
child: Image.asset(
properties.path,
width: properties.getScaledWidth(widget.sunSize),
height: properties.getScaledHeight(widget.sunSize),
),
));

// Positioned only

return Positioned(
left: horizontal,
top: vertical,
child: Image.asset(
properties.path,
width: properties.getScaledWidth(widget.sunSize),
height: properties.getScaledHeight(widget.sunSize),
));

// Opacity only

return Positioned(
left: (screenWidth * 0.5) + (widget.sunSize * properties.tween[1]),
top: vertical,
child: Opacity(
opacity: opacity.value,
child: Image.asset(
properties.path,
width: properties.getScaledWidth(widget.sunSize),
height: properties.getScaledHeight(widget.sunSize),
),
));
}

@override
dispose() {
controller.dispose();
controller2.dispose();
super.dispose();
}

void _startAnimation() {
controller = AnimationController(
duration: const Duration(milliseconds: 5000), vsync: this);

controller2 = AnimationController(
duration: const Duration(milliseconds: 5000), vsync: this);

position = Tween(
begin: widget.properties.tween[0], end: widget.properties.tween[1])
.animate(
new CurvedAnimation(parent: controller, curve: Curves.decelerate))
..addListener(() => setState(() {}));

opacity = Tween(begin: 0.0, end: 1.0).animate(controller2)
..addListener(() => setState(() {}));

controller.forward();
controller2.forward();
}
}









share|improve this question





























    2















    I have a weird flutter issue with a certain animation I'm trying to create.



    I am trying to animate an image onto the screen.
    I want it to move on the x-axis, and I want it to slowly fade in as well.



    So I figured - Positioned and Opacity, and animate their value with a tween.



    Both the Positioned and Opacity widgets work great on their own, but when I combine the two - I get a weird animation, that only starts to draw after a while (about 3 seconds).



    I tried printing the animation.value and it seems to be fine, slowly climbing from 0.0 to 1.0 - but the clouds suddenly appear only after like 3 seconds.



    I tried separating them to different controllers, thought that maybe somehow that was the culprit, but nope.



    TLDR Videos:



    Opacity Animation Only



    Positioned Animation Only



    Both Animations Combined - NOT GOOD



    Here's the widget's code:



    import 'package:app/weather/widgets/CloudProperties.dart';
    import 'package:flutter/widgets.dart';

    class WeatherCloudWidget extends StatefulWidget {
    final double sunSize;
    final CloudProperties properties;

    WeatherCloudWidget({Key key, this.properties, this.sunSize})
    : super(key: key);

    @override
    State<StatefulWidget> createState() => _WeatherCloudWidget();
    }

    class _WeatherCloudWidget extends State<WeatherCloudWidget>
    with TickerProviderStateMixin {
    AnimationController controller;
    AnimationController controller2;

    Animation<double> position;
    Animation<double> opacity;

    @override
    initState() {
    super.initState();
    _startAnimation();
    }

    @override
    Widget build(BuildContext context) {
    // screen width and height
    final screenWidth = MediaQuery.of(context).size.width;
    final screenHeight = MediaQuery.of(context).size.height;

    final properties = widget.properties;

    var vertical =
    screenHeight * 0.5 + (widget.sunSize * properties.verticalOffset * -1);

    var horizontal = (screenWidth * 0.5) + (widget.sunSize * position.value);

    print(opacity.value);

    // both Positioned & Opacity widgets

    return Positioned(
    left: horizontal,
    top: vertical,
    child: Opacity(
    opacity: opacity.value,
    child: Image.asset(
    properties.path,
    width: properties.getScaledWidth(widget.sunSize),
    height: properties.getScaledHeight(widget.sunSize),
    ),
    ));

    // Positioned only

    return Positioned(
    left: horizontal,
    top: vertical,
    child: Image.asset(
    properties.path,
    width: properties.getScaledWidth(widget.sunSize),
    height: properties.getScaledHeight(widget.sunSize),
    ));

    // Opacity only

    return Positioned(
    left: (screenWidth * 0.5) + (widget.sunSize * properties.tween[1]),
    top: vertical,
    child: Opacity(
    opacity: opacity.value,
    child: Image.asset(
    properties.path,
    width: properties.getScaledWidth(widget.sunSize),
    height: properties.getScaledHeight(widget.sunSize),
    ),
    ));
    }

    @override
    dispose() {
    controller.dispose();
    controller2.dispose();
    super.dispose();
    }

    void _startAnimation() {
    controller = AnimationController(
    duration: const Duration(milliseconds: 5000), vsync: this);

    controller2 = AnimationController(
    duration: const Duration(milliseconds: 5000), vsync: this);

    position = Tween(
    begin: widget.properties.tween[0], end: widget.properties.tween[1])
    .animate(
    new CurvedAnimation(parent: controller, curve: Curves.decelerate))
    ..addListener(() => setState(() {}));

    opacity = Tween(begin: 0.0, end: 1.0).animate(controller2)
    ..addListener(() => setState(() {}));

    controller.forward();
    controller2.forward();
    }
    }









    share|improve this question



























      2












      2








      2


      1






      I have a weird flutter issue with a certain animation I'm trying to create.



      I am trying to animate an image onto the screen.
      I want it to move on the x-axis, and I want it to slowly fade in as well.



      So I figured - Positioned and Opacity, and animate their value with a tween.



      Both the Positioned and Opacity widgets work great on their own, but when I combine the two - I get a weird animation, that only starts to draw after a while (about 3 seconds).



      I tried printing the animation.value and it seems to be fine, slowly climbing from 0.0 to 1.0 - but the clouds suddenly appear only after like 3 seconds.



      I tried separating them to different controllers, thought that maybe somehow that was the culprit, but nope.



      TLDR Videos:



      Opacity Animation Only



      Positioned Animation Only



      Both Animations Combined - NOT GOOD



      Here's the widget's code:



      import 'package:app/weather/widgets/CloudProperties.dart';
      import 'package:flutter/widgets.dart';

      class WeatherCloudWidget extends StatefulWidget {
      final double sunSize;
      final CloudProperties properties;

      WeatherCloudWidget({Key key, this.properties, this.sunSize})
      : super(key: key);

      @override
      State<StatefulWidget> createState() => _WeatherCloudWidget();
      }

      class _WeatherCloudWidget extends State<WeatherCloudWidget>
      with TickerProviderStateMixin {
      AnimationController controller;
      AnimationController controller2;

      Animation<double> position;
      Animation<double> opacity;

      @override
      initState() {
      super.initState();
      _startAnimation();
      }

      @override
      Widget build(BuildContext context) {
      // screen width and height
      final screenWidth = MediaQuery.of(context).size.width;
      final screenHeight = MediaQuery.of(context).size.height;

      final properties = widget.properties;

      var vertical =
      screenHeight * 0.5 + (widget.sunSize * properties.verticalOffset * -1);

      var horizontal = (screenWidth * 0.5) + (widget.sunSize * position.value);

      print(opacity.value);

      // both Positioned & Opacity widgets

      return Positioned(
      left: horizontal,
      top: vertical,
      child: Opacity(
      opacity: opacity.value,
      child: Image.asset(
      properties.path,
      width: properties.getScaledWidth(widget.sunSize),
      height: properties.getScaledHeight(widget.sunSize),
      ),
      ));

      // Positioned only

      return Positioned(
      left: horizontal,
      top: vertical,
      child: Image.asset(
      properties.path,
      width: properties.getScaledWidth(widget.sunSize),
      height: properties.getScaledHeight(widget.sunSize),
      ));

      // Opacity only

      return Positioned(
      left: (screenWidth * 0.5) + (widget.sunSize * properties.tween[1]),
      top: vertical,
      child: Opacity(
      opacity: opacity.value,
      child: Image.asset(
      properties.path,
      width: properties.getScaledWidth(widget.sunSize),
      height: properties.getScaledHeight(widget.sunSize),
      ),
      ));
      }

      @override
      dispose() {
      controller.dispose();
      controller2.dispose();
      super.dispose();
      }

      void _startAnimation() {
      controller = AnimationController(
      duration: const Duration(milliseconds: 5000), vsync: this);

      controller2 = AnimationController(
      duration: const Duration(milliseconds: 5000), vsync: this);

      position = Tween(
      begin: widget.properties.tween[0], end: widget.properties.tween[1])
      .animate(
      new CurvedAnimation(parent: controller, curve: Curves.decelerate))
      ..addListener(() => setState(() {}));

      opacity = Tween(begin: 0.0, end: 1.0).animate(controller2)
      ..addListener(() => setState(() {}));

      controller.forward();
      controller2.forward();
      }
      }









      share|improve this question
















      I have a weird flutter issue with a certain animation I'm trying to create.



      I am trying to animate an image onto the screen.
      I want it to move on the x-axis, and I want it to slowly fade in as well.



      So I figured - Positioned and Opacity, and animate their value with a tween.



      Both the Positioned and Opacity widgets work great on their own, but when I combine the two - I get a weird animation, that only starts to draw after a while (about 3 seconds).



      I tried printing the animation.value and it seems to be fine, slowly climbing from 0.0 to 1.0 - but the clouds suddenly appear only after like 3 seconds.



      I tried separating them to different controllers, thought that maybe somehow that was the culprit, but nope.



      TLDR Videos:



      Opacity Animation Only



      Positioned Animation Only



      Both Animations Combined - NOT GOOD



      Here's the widget's code:



      import 'package:app/weather/widgets/CloudProperties.dart';
      import 'package:flutter/widgets.dart';

      class WeatherCloudWidget extends StatefulWidget {
      final double sunSize;
      final CloudProperties properties;

      WeatherCloudWidget({Key key, this.properties, this.sunSize})
      : super(key: key);

      @override
      State<StatefulWidget> createState() => _WeatherCloudWidget();
      }

      class _WeatherCloudWidget extends State<WeatherCloudWidget>
      with TickerProviderStateMixin {
      AnimationController controller;
      AnimationController controller2;

      Animation<double> position;
      Animation<double> opacity;

      @override
      initState() {
      super.initState();
      _startAnimation();
      }

      @override
      Widget build(BuildContext context) {
      // screen width and height
      final screenWidth = MediaQuery.of(context).size.width;
      final screenHeight = MediaQuery.of(context).size.height;

      final properties = widget.properties;

      var vertical =
      screenHeight * 0.5 + (widget.sunSize * properties.verticalOffset * -1);

      var horizontal = (screenWidth * 0.5) + (widget.sunSize * position.value);

      print(opacity.value);

      // both Positioned & Opacity widgets

      return Positioned(
      left: horizontal,
      top: vertical,
      child: Opacity(
      opacity: opacity.value,
      child: Image.asset(
      properties.path,
      width: properties.getScaledWidth(widget.sunSize),
      height: properties.getScaledHeight(widget.sunSize),
      ),
      ));

      // Positioned only

      return Positioned(
      left: horizontal,
      top: vertical,
      child: Image.asset(
      properties.path,
      width: properties.getScaledWidth(widget.sunSize),
      height: properties.getScaledHeight(widget.sunSize),
      ));

      // Opacity only

      return Positioned(
      left: (screenWidth * 0.5) + (widget.sunSize * properties.tween[1]),
      top: vertical,
      child: Opacity(
      opacity: opacity.value,
      child: Image.asset(
      properties.path,
      width: properties.getScaledWidth(widget.sunSize),
      height: properties.getScaledHeight(widget.sunSize),
      ),
      ));
      }

      @override
      dispose() {
      controller.dispose();
      controller2.dispose();
      super.dispose();
      }

      void _startAnimation() {
      controller = AnimationController(
      duration: const Duration(milliseconds: 5000), vsync: this);

      controller2 = AnimationController(
      duration: const Duration(milliseconds: 5000), vsync: this);

      position = Tween(
      begin: widget.properties.tween[0], end: widget.properties.tween[1])
      .animate(
      new CurvedAnimation(parent: controller, curve: Curves.decelerate))
      ..addListener(() => setState(() {}));

      opacity = Tween(begin: 0.0, end: 1.0).animate(controller2)
      ..addListener(() => setState(() {}));

      controller.forward();
      controller2.forward();
      }
      }






      dart flutter flutter-layout flutter-animation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 18 '18 at 21:00







      sofakingforever

















      asked Nov 18 '18 at 19:51









      sofakingforeversofakingforever

      419211




      419211
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Alright guys. I managed to sort this using SlideTransition and FadeTransition.
          I guess we should only use Transition widgets for... transitions? while things like Positioned and Opacity are for more static widgets? Not sure...



          What it looks like: https://youtu.be/hj7PkjXrgfg



          Anyways, here's the replacement code, if anyone's looking for reference:



          class WeatherCloudWidget extends StatefulWidget {
          final double sunSize;
          final CloudProperties properties;

          WeatherCloudWidget({Key key, this.properties, this.sunSize})
          : super(key: key);

          @override
          State<StatefulWidget> createState() => _WeatherCloudWidget();
          }

          class _WeatherCloudWidget extends State<WeatherCloudWidget>
          with TickerProviderStateMixin {
          AnimationController controller;
          Animation<Offset> position;
          Animation<double> opacity;

          final alphaTween = new Tween(begin: 0.0, end: 1.0);

          @override
          initState() {
          super.initState();
          _startAnimation();
          }

          @override
          Widget build(BuildContext context) {
          // screen width and height
          final screenWidth = MediaQuery.of(context).size.width;
          final screenHeight = MediaQuery.of(context).size.height;

          final properties = widget.properties;

          var vertical = (screenHeight * 0.5) +
          (widget.sunSize * properties.verticalOffset * -1);

          var horizontal =
          (screenWidth * 0.5) + (widget.sunSize * properties.tweenEnd);

          return Positioned(
          left: horizontal,
          top: vertical,
          child: SlideTransition(
          position: position,
          child: FadeTransition(
          opacity: opacity,
          child: Image.asset(
          properties.path,
          width: properties.getScaledWidth(widget.sunSize),
          height: properties.getScaledHeight(widget.sunSize),
          ),
          )),
          );
          }

          @override
          dispose() {
          controller.dispose();
          super.dispose();
          }

          void _startAnimation() {
          controller = AnimationController(
          duration: const Duration(milliseconds: 2000), vsync: this);

          position = new Tween<Offset>(
          begin: new Offset(widget.properties.tweenStart, 0.0),
          end: new Offset(0.0, 0.0),
          ).animate(new CurvedAnimation(parent: controller, curve: Curves.decelerate));

          opacity = alphaTween.animate(controller);

          controller.forward();
          }
          }





          share|improve this answer





















          • 1





            you dont need addListener and setState in the listener (it rebuilds WeatherCloudWidget) - controller.forward(); is just enough

            – pskink
            Nov 19 '18 at 7:48








          • 1





            do you mind making a video of the new version? (i'm curious) :)

            – Feu
            Nov 19 '18 at 23:28











          • Hey @Feu, i've added the video to the answer.

            – sofakingforever
            Nov 21 '18 at 14:32











          • @pskink - you're right of course! It was something I tried when the animations didn't work, and forgot to remove this.

            – sofakingforever
            Nov 21 '18 at 14:34











          • so in theory your WeatherCloudWidget could be now StatelessWidget? or not?

            – pskink
            Nov 21 '18 at 14:40













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364830%2fproblems-with-multiple-tween-animations-in-flutter-videos-included%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Alright guys. I managed to sort this using SlideTransition and FadeTransition.
          I guess we should only use Transition widgets for... transitions? while things like Positioned and Opacity are for more static widgets? Not sure...



          What it looks like: https://youtu.be/hj7PkjXrgfg



          Anyways, here's the replacement code, if anyone's looking for reference:



          class WeatherCloudWidget extends StatefulWidget {
          final double sunSize;
          final CloudProperties properties;

          WeatherCloudWidget({Key key, this.properties, this.sunSize})
          : super(key: key);

          @override
          State<StatefulWidget> createState() => _WeatherCloudWidget();
          }

          class _WeatherCloudWidget extends State<WeatherCloudWidget>
          with TickerProviderStateMixin {
          AnimationController controller;
          Animation<Offset> position;
          Animation<double> opacity;

          final alphaTween = new Tween(begin: 0.0, end: 1.0);

          @override
          initState() {
          super.initState();
          _startAnimation();
          }

          @override
          Widget build(BuildContext context) {
          // screen width and height
          final screenWidth = MediaQuery.of(context).size.width;
          final screenHeight = MediaQuery.of(context).size.height;

          final properties = widget.properties;

          var vertical = (screenHeight * 0.5) +
          (widget.sunSize * properties.verticalOffset * -1);

          var horizontal =
          (screenWidth * 0.5) + (widget.sunSize * properties.tweenEnd);

          return Positioned(
          left: horizontal,
          top: vertical,
          child: SlideTransition(
          position: position,
          child: FadeTransition(
          opacity: opacity,
          child: Image.asset(
          properties.path,
          width: properties.getScaledWidth(widget.sunSize),
          height: properties.getScaledHeight(widget.sunSize),
          ),
          )),
          );
          }

          @override
          dispose() {
          controller.dispose();
          super.dispose();
          }

          void _startAnimation() {
          controller = AnimationController(
          duration: const Duration(milliseconds: 2000), vsync: this);

          position = new Tween<Offset>(
          begin: new Offset(widget.properties.tweenStart, 0.0),
          end: new Offset(0.0, 0.0),
          ).animate(new CurvedAnimation(parent: controller, curve: Curves.decelerate));

          opacity = alphaTween.animate(controller);

          controller.forward();
          }
          }





          share|improve this answer





















          • 1





            you dont need addListener and setState in the listener (it rebuilds WeatherCloudWidget) - controller.forward(); is just enough

            – pskink
            Nov 19 '18 at 7:48








          • 1





            do you mind making a video of the new version? (i'm curious) :)

            – Feu
            Nov 19 '18 at 23:28











          • Hey @Feu, i've added the video to the answer.

            – sofakingforever
            Nov 21 '18 at 14:32











          • @pskink - you're right of course! It was something I tried when the animations didn't work, and forgot to remove this.

            – sofakingforever
            Nov 21 '18 at 14:34











          • so in theory your WeatherCloudWidget could be now StatelessWidget? or not?

            – pskink
            Nov 21 '18 at 14:40


















          1














          Alright guys. I managed to sort this using SlideTransition and FadeTransition.
          I guess we should only use Transition widgets for... transitions? while things like Positioned and Opacity are for more static widgets? Not sure...



          What it looks like: https://youtu.be/hj7PkjXrgfg



          Anyways, here's the replacement code, if anyone's looking for reference:



          class WeatherCloudWidget extends StatefulWidget {
          final double sunSize;
          final CloudProperties properties;

          WeatherCloudWidget({Key key, this.properties, this.sunSize})
          : super(key: key);

          @override
          State<StatefulWidget> createState() => _WeatherCloudWidget();
          }

          class _WeatherCloudWidget extends State<WeatherCloudWidget>
          with TickerProviderStateMixin {
          AnimationController controller;
          Animation<Offset> position;
          Animation<double> opacity;

          final alphaTween = new Tween(begin: 0.0, end: 1.0);

          @override
          initState() {
          super.initState();
          _startAnimation();
          }

          @override
          Widget build(BuildContext context) {
          // screen width and height
          final screenWidth = MediaQuery.of(context).size.width;
          final screenHeight = MediaQuery.of(context).size.height;

          final properties = widget.properties;

          var vertical = (screenHeight * 0.5) +
          (widget.sunSize * properties.verticalOffset * -1);

          var horizontal =
          (screenWidth * 0.5) + (widget.sunSize * properties.tweenEnd);

          return Positioned(
          left: horizontal,
          top: vertical,
          child: SlideTransition(
          position: position,
          child: FadeTransition(
          opacity: opacity,
          child: Image.asset(
          properties.path,
          width: properties.getScaledWidth(widget.sunSize),
          height: properties.getScaledHeight(widget.sunSize),
          ),
          )),
          );
          }

          @override
          dispose() {
          controller.dispose();
          super.dispose();
          }

          void _startAnimation() {
          controller = AnimationController(
          duration: const Duration(milliseconds: 2000), vsync: this);

          position = new Tween<Offset>(
          begin: new Offset(widget.properties.tweenStart, 0.0),
          end: new Offset(0.0, 0.0),
          ).animate(new CurvedAnimation(parent: controller, curve: Curves.decelerate));

          opacity = alphaTween.animate(controller);

          controller.forward();
          }
          }





          share|improve this answer





















          • 1





            you dont need addListener and setState in the listener (it rebuilds WeatherCloudWidget) - controller.forward(); is just enough

            – pskink
            Nov 19 '18 at 7:48








          • 1





            do you mind making a video of the new version? (i'm curious) :)

            – Feu
            Nov 19 '18 at 23:28











          • Hey @Feu, i've added the video to the answer.

            – sofakingforever
            Nov 21 '18 at 14:32











          • @pskink - you're right of course! It was something I tried when the animations didn't work, and forgot to remove this.

            – sofakingforever
            Nov 21 '18 at 14:34











          • so in theory your WeatherCloudWidget could be now StatelessWidget? or not?

            – pskink
            Nov 21 '18 at 14:40
















          1












          1








          1







          Alright guys. I managed to sort this using SlideTransition and FadeTransition.
          I guess we should only use Transition widgets for... transitions? while things like Positioned and Opacity are for more static widgets? Not sure...



          What it looks like: https://youtu.be/hj7PkjXrgfg



          Anyways, here's the replacement code, if anyone's looking for reference:



          class WeatherCloudWidget extends StatefulWidget {
          final double sunSize;
          final CloudProperties properties;

          WeatherCloudWidget({Key key, this.properties, this.sunSize})
          : super(key: key);

          @override
          State<StatefulWidget> createState() => _WeatherCloudWidget();
          }

          class _WeatherCloudWidget extends State<WeatherCloudWidget>
          with TickerProviderStateMixin {
          AnimationController controller;
          Animation<Offset> position;
          Animation<double> opacity;

          final alphaTween = new Tween(begin: 0.0, end: 1.0);

          @override
          initState() {
          super.initState();
          _startAnimation();
          }

          @override
          Widget build(BuildContext context) {
          // screen width and height
          final screenWidth = MediaQuery.of(context).size.width;
          final screenHeight = MediaQuery.of(context).size.height;

          final properties = widget.properties;

          var vertical = (screenHeight * 0.5) +
          (widget.sunSize * properties.verticalOffset * -1);

          var horizontal =
          (screenWidth * 0.5) + (widget.sunSize * properties.tweenEnd);

          return Positioned(
          left: horizontal,
          top: vertical,
          child: SlideTransition(
          position: position,
          child: FadeTransition(
          opacity: opacity,
          child: Image.asset(
          properties.path,
          width: properties.getScaledWidth(widget.sunSize),
          height: properties.getScaledHeight(widget.sunSize),
          ),
          )),
          );
          }

          @override
          dispose() {
          controller.dispose();
          super.dispose();
          }

          void _startAnimation() {
          controller = AnimationController(
          duration: const Duration(milliseconds: 2000), vsync: this);

          position = new Tween<Offset>(
          begin: new Offset(widget.properties.tweenStart, 0.0),
          end: new Offset(0.0, 0.0),
          ).animate(new CurvedAnimation(parent: controller, curve: Curves.decelerate));

          opacity = alphaTween.animate(controller);

          controller.forward();
          }
          }





          share|improve this answer















          Alright guys. I managed to sort this using SlideTransition and FadeTransition.
          I guess we should only use Transition widgets for... transitions? while things like Positioned and Opacity are for more static widgets? Not sure...



          What it looks like: https://youtu.be/hj7PkjXrgfg



          Anyways, here's the replacement code, if anyone's looking for reference:



          class WeatherCloudWidget extends StatefulWidget {
          final double sunSize;
          final CloudProperties properties;

          WeatherCloudWidget({Key key, this.properties, this.sunSize})
          : super(key: key);

          @override
          State<StatefulWidget> createState() => _WeatherCloudWidget();
          }

          class _WeatherCloudWidget extends State<WeatherCloudWidget>
          with TickerProviderStateMixin {
          AnimationController controller;
          Animation<Offset> position;
          Animation<double> opacity;

          final alphaTween = new Tween(begin: 0.0, end: 1.0);

          @override
          initState() {
          super.initState();
          _startAnimation();
          }

          @override
          Widget build(BuildContext context) {
          // screen width and height
          final screenWidth = MediaQuery.of(context).size.width;
          final screenHeight = MediaQuery.of(context).size.height;

          final properties = widget.properties;

          var vertical = (screenHeight * 0.5) +
          (widget.sunSize * properties.verticalOffset * -1);

          var horizontal =
          (screenWidth * 0.5) + (widget.sunSize * properties.tweenEnd);

          return Positioned(
          left: horizontal,
          top: vertical,
          child: SlideTransition(
          position: position,
          child: FadeTransition(
          opacity: opacity,
          child: Image.asset(
          properties.path,
          width: properties.getScaledWidth(widget.sunSize),
          height: properties.getScaledHeight(widget.sunSize),
          ),
          )),
          );
          }

          @override
          dispose() {
          controller.dispose();
          super.dispose();
          }

          void _startAnimation() {
          controller = AnimationController(
          duration: const Duration(milliseconds: 2000), vsync: this);

          position = new Tween<Offset>(
          begin: new Offset(widget.properties.tweenStart, 0.0),
          end: new Offset(0.0, 0.0),
          ).animate(new CurvedAnimation(parent: controller, curve: Curves.decelerate));

          opacity = alphaTween.animate(controller);

          controller.forward();
          }
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 '18 at 14:32

























          answered Nov 18 '18 at 21:25









          sofakingforeversofakingforever

          419211




          419211








          • 1





            you dont need addListener and setState in the listener (it rebuilds WeatherCloudWidget) - controller.forward(); is just enough

            – pskink
            Nov 19 '18 at 7:48








          • 1





            do you mind making a video of the new version? (i'm curious) :)

            – Feu
            Nov 19 '18 at 23:28











          • Hey @Feu, i've added the video to the answer.

            – sofakingforever
            Nov 21 '18 at 14:32











          • @pskink - you're right of course! It was something I tried when the animations didn't work, and forgot to remove this.

            – sofakingforever
            Nov 21 '18 at 14:34











          • so in theory your WeatherCloudWidget could be now StatelessWidget? or not?

            – pskink
            Nov 21 '18 at 14:40
















          • 1





            you dont need addListener and setState in the listener (it rebuilds WeatherCloudWidget) - controller.forward(); is just enough

            – pskink
            Nov 19 '18 at 7:48








          • 1





            do you mind making a video of the new version? (i'm curious) :)

            – Feu
            Nov 19 '18 at 23:28











          • Hey @Feu, i've added the video to the answer.

            – sofakingforever
            Nov 21 '18 at 14:32











          • @pskink - you're right of course! It was something I tried when the animations didn't work, and forgot to remove this.

            – sofakingforever
            Nov 21 '18 at 14:34











          • so in theory your WeatherCloudWidget could be now StatelessWidget? or not?

            – pskink
            Nov 21 '18 at 14:40










          1




          1





          you dont need addListener and setState in the listener (it rebuilds WeatherCloudWidget) - controller.forward(); is just enough

          – pskink
          Nov 19 '18 at 7:48







          you dont need addListener and setState in the listener (it rebuilds WeatherCloudWidget) - controller.forward(); is just enough

          – pskink
          Nov 19 '18 at 7:48






          1




          1





          do you mind making a video of the new version? (i'm curious) :)

          – Feu
          Nov 19 '18 at 23:28





          do you mind making a video of the new version? (i'm curious) :)

          – Feu
          Nov 19 '18 at 23:28













          Hey @Feu, i've added the video to the answer.

          – sofakingforever
          Nov 21 '18 at 14:32





          Hey @Feu, i've added the video to the answer.

          – sofakingforever
          Nov 21 '18 at 14:32













          @pskink - you're right of course! It was something I tried when the animations didn't work, and forgot to remove this.

          – sofakingforever
          Nov 21 '18 at 14:34





          @pskink - you're right of course! It was something I tried when the animations didn't work, and forgot to remove this.

          – sofakingforever
          Nov 21 '18 at 14:34













          so in theory your WeatherCloudWidget could be now StatelessWidget? or not?

          – pskink
          Nov 21 '18 at 14:40







          so in theory your WeatherCloudWidget could be now StatelessWidget? or not?

          – pskink
          Nov 21 '18 at 14:40






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364830%2fproblems-with-multiple-tween-animations-in-flutter-videos-included%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()