GIfatahTH / animator

A Flutter library that makes animation easer. It allows for separation of animation setup from the User Interface.
BSD 3-Clause "New" or "Revised" License
227 stars 28 forks source link

runtime error after updating to Flutter 1.9 and animator 1.0 #20

Closed ride4sun closed 5 years ago

ride4sun commented 5 years ago

(10993): 2642 2019-09-11 11:14:38.719961 SEVERE home_test.sentry_error_reporter: Context: building StateWithMixinBuilder(state: _StateBuilderStateSingleTickerMix#1aa60(ticker inactive)), library: widgets library I/flutter (10993): error: _StateBuilderStateSingleTickerMix is a SingleTickerProviderStateMixin but multiple tickers were created. I/flutter (10993): A SingleTickerProviderStateMixin can only be used as a TickerProvider once. If a State is used for multiple AnimationController objects, or if it is passed to other objects and those objects might use it more than one time in total, then instead of mixing in a SingleTickerProviderStateMixin, use a regular TickerProviderStateMixin. I/flutter (10993): #0 SingleTickerProviderStateMixin.createTicker. (package:flutter/src/widgets/ticker_provider.dart:85:7) I/flutter (10993): #1 SingleTickerProviderStateMixin.createTicker (package:flutter/src/widgets/ticker_provider.dart:92:6) I/flutter (10993): #2 new AnimationController (package:flutter/src/animation/animation_controller.dart:245:21) I/flutter (10993): #3 Animate.setController (package:animator/src/animate.dart:35:18) I/flutter (10993): #4 StatesRebuilderWithAnimator.initAnimation (package:animator/src/states_rebuilder_with_animator.dart:54:14) I/flutter (10993): #5 _AnimatorState.build. (package:animator/src/animator.dart:174:23) I/flutter (10993): #6 _StateBuilderStateSingleTickerMix.build. (package:states_rebuilder/src/state_with_mixin_builder.dart) I/flutter (10993): #7 _StateBuilderState.initState (package:states_rebuilder/src/state_builder.dart:146:42) I/flutter (10993): #8 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4068:58) I/flutter (10993): #9 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3919:5) I/flutter (10993): #10 Element

all my animations are wrapped in this class:

import 'package:elm_bluetooth_bloc/model/units/unit.dart';
import 'package:flutter/material.dart';
import 'package:utilities/utilities.dart' show StreamValue;

class StreamAnimatorBuilder<T extends Unit> extends StatelessWidget {
  final StreamValue<T> streamValue;
  final Widget Function(double) builder;
  final Duration animationDuration;
  final Curve curve;

  StreamAnimatorBuilder(
      {@required this.streamValue,
      @required this.builder,
      this.animationDuration = const Duration(milliseconds: 250),
      this.curve = Curves.easeInOut});

  @override
  Widget build(BuildContext context) => StreamBuilder<T>(
        stream: streamValue.stream,
        initialData: null,
        builder: (context, snapshot) {
          Unit previous = streamValue.previousValue;
          double previousValue = double.parse(previous.value);
          Unit newValue = streamValue.value;
          double value = double.parse(newValue.value);

          if (snapshot.data == null ||
              snapshot.hasError ||
              previous == null ||
              newValue == null) {
            return Container();
          } else {

            //print("ANIMATION VALUES: $previousValue , $value");

            return Animator(
                resetAnimationOnRebuild: true,
                tween: Tween<double>(begin: previousValue, end: value),
                cycles: 1,
                duration: animationDuration,
                curve: curve,
                builder: (anim) => builder(anim.value));
          }
        },
      );
}

If I downgrade animator to 0.1.1 and stay on 1.9 I get this build errors:

Launching lib\main.dart on moto g 7 in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

Compiler message:
/C:/Users/ride4/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/animator-0.1.4/lib/animator.dart:494:27: Error: Method not found: 'StatesRebuilder.addToListeners'.
          StatesRebuilder.addToListeners(
                          ^^^^^^^^^^^^^^
/C:/Users/ride4/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/animator-0.1.4/lib/animator.dart:559:27: Error: Method not found: 'StatesRebuilder.removeFromListeners'.
          StatesRebuilder.removeFromListeners(b, widget.name, "$hashCode");
                          ^^^^^^^^^^^^^^^^^^^
Compiler failed on C:\Projects\obdchk\lib\main.dart
Finished with error: Gradle task assembleDebug failed with exit code 1
GIfatahTH commented 5 years ago

I/flutter (10993): error: _StateBuilderStateSingleTickerMix is a SingleTickerProviderStateMixin but multiple tickers were created.

I think it is not related to Flutter 1.9 version. The default TickerProvider of Animator is of type SingleTickerProviderStateMixin. The error complains that single ticker is used to create many tickers. To solve this you have to option: 1- define the parameter tickerMixin of the animator: to be equal to TickerMixin.tickerProviderStateMixin

Animator(
               tickerMixin : TickerMixin.tickerProviderStateMixin,
                resetAnimationOnRebuild: true,
                tween: Tween<double>(begin: previousValue, end: value),
                cycles: 1,
                duration: animationDuration,
                curve: curve,
                builder: (anim) => builder(anim.value));

2- Or add a UniqueKey to the animator widget:

Animator(
              key: UniqueKey(),
                resetAnimationOnRebuild: true,
                tween: Tween<double>(begin: previousValue, end: value),
                cycles: 1,
                duration: animationDuration,
                curve: curve,
                builder: (anim) => builder(anim.value));
GIfatahTH commented 5 years ago

I updated the package to make it the default behavior. Now you do not have to use Unique Key () or tickerMixin.

Animator(
                resetAnimationOnRebuild: true,
                Tween: Tween(begin: previousValue, end: value),
                cycles: 1,
                duration: animationDuration,
                curve: curve,
                builder: (anim) => builder(anim.value));

Your code will work without any modification. Please confirm that

ride4sun commented 5 years ago

Perfect, thx, I was just wondering about that. I will try on Monday to go back to 1.9 / 1.0. I will report back.

On Thu, Sep 12, 2019, 13:08 MELLATI Fatah notifications@github.com wrote:

I updated the package to make it the default behavior. Now you do not have to use Unique Key () or tickerMixin.

Animator( resetAnimationOnRebuild: true, Tween: Tween(begin: previousValue, end: value), cycles: 1, duration: animationDuration, curve: curve, builder: (anim) => builder(anim.value));

Your code will work without any modification. Please confirm that

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/GIfatahTH/animator/issues/20?email_source=notifications&email_token=AB3BZ2ZGANBCWKJCPGAATGTQJKOTVA5CNFSM4IVXLJY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6TDDSY#issuecomment-530985419, or mute the thread https://github.com/notifications/unsubscribe-auth/AB3BZ22YHGCVOWVJUYEGSFTQJKOTVANCNFSM4IVXLJYQ .

ride4sun commented 5 years ago

@GIfatahTH works fine with the latest update without modification. Thx. This can be closed.