Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid curve endpoint at 1.0 #23

Closed
saikiranVu opened this issue Apr 22, 2020 · 5 comments · Fixed by #27
Closed

Invalid curve endpoint at 1.0 #23

saikiranVu opened this issue Apr 22, 2020 · 5 comments · Fixed by #27

Comments

@saikiranVu
Copy link

Invalid curve endpoint at 1.0

Curves must map 0.0 to near zero and 1.0 to near one but ShakeCurve mapped 1.0 to 3.6739403974420594e-16, which is near 0.0.

@OverRide
initState() {
super.initState();
streamSubscription = widget.shouldTriggerVerification.listen((isValid) => _showValidation(isValid));
controller = AnimationController(duration: const Duration(milliseconds: 500), vsync: this);
final Animation curve = CurvedAnimation(parent: controller, curve: ShakeCurve());
animation = Tween(begin: 0.0, end: ### 10.0).animate(curve)
..addStatusListener((status) {
if (status == AnimationStatus.completed) {
setState(() {
enteredPasscode = '';
controller.value = 0;
});
}
})
..addListener(() {
setState(() {
// the animation object’s value is the changed state
});
});
}

@xPutnikx
Copy link
Owner

Hi, @saikiranVu
Can you explain what is the problem? It's not really clear

@ernestowusu
Copy link

Another exception was thrown: Invalid curve endpoint at 1.0. I get this same error on IOS when a passcode is typed and the shaking animation is triggered

@maginc
Copy link

maginc commented Aug 25, 2020

Sometimes i have same glitch, error from console:

The following assertion was thrown building LayoutBuilder:
Invalid curve endpoint at 1.0.

Curves must map 0.0 to near zero and 1.0 to near one but ShakeCurve mapped 1.0 to 3.6739403974420594e-16, which is near 0.0.
The relevant error-causing widget was: 
 OrientationBuilder file:///Users/me/AndroidStudioProjects/myapp/lib/common/pin_input_widget/passcode_screen.dart:90:16
When the exception was thrown, this was the stack: 
#0      CurvedAnimation.value.<anonymous closure> (package:flutter/src/animation/animations.dart:442:11)
#1      CurvedAnimation.value (package:flutter/src/animation/animations.dart:450:8)
#2      Animatable.evaluate (package:flutter/src/animation/tween.dart:54:66)
#3      _AnimatedEvaluation.value (package:flutter/src/animation/tween.dart:88:31)
#4      _PasscodeScreenState._buildCircles (package:myapp/common/pin_input_widget/passcode_screen.dart:196:31)
...
═══════════════════════════════════════════════════════════════════════════════```

I don't know how to replicate this, as it appears randomly.

@ssanderson
Copy link

This assertion triggers reliably for me if I enter a pin incorrectly on the PasscodeScreen using flutter_test. It looks like the issue here is that flutter's Curve class expects you to define a transform function that ranges from 0 to 1 as a function of t going from 0 to 1.

From https://api.flutter.dev/flutter/animation/Curve-class.html:

A Curve must map t=0.0 to 0.0 and t=1.0 to 1.0.

The current ShakeCurve definition is

class ShakeCurve extends Curve {
  @override
  double transform(double t) {
    //t from 0.0 to 1.0
    return sin(t * 3 * pi).abs();
  }
}

Which doesn't satisfy the required property. Specificaly sin(3 * pi).abs() is 0, not 1.

If I change the function to be sin(2.5 * pi).abs() instead, the assertion no longer triggers.

@ZephyrVentum
Copy link

ZephyrVentum commented Jan 14, 2024

Thanks, it helped to figure out what was wrong in my case. Working code for me now:

class CurveWave extends Curve {
  const CurveWave();

  @override
  double transform(double t) {
    if (t == 0) {
      return 0.01;
    } else if (t == 1) {
      return 0.99;
    }
    return math.sin(t * math.pi);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants