Invalid curve endpoint at 1.0
saikiranVu opened this issue · 5 comments
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
});
});
}
Hi, @saikiranVu
Can you explain what is the problem? It's not really clear
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
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.
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.
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);
}
}