Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/flutter/lib/src/animation/curves.dart
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@ class Cubic extends Curve {

@override
double transformInternal(double t) {
if (t.isNaN) {
throw ArgumentError.value(t, 't', 'must not be NaN');
}
if (t <= 0.0) {
return 0.0;
}
if (t >= 1.0) {
return 1.0;
}
var start = 0.0;
var end = 1.0;
while (true) {
Expand Down
10 changes: 10 additions & 0 deletions packages/flutter/test/animation/curves_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ void main() {
expect(test.transform(0.166666), equals(0.4));
});

// Regression test for https://github.com/flutter/flutter/issues/171364.
test('Cubic transformInternal clamps values outside the unit interval', () {
expect(Curves.easeOut.transformInternal(2.0), 1.0);
expect(Curves.easeOut.transformInternal(-1.0), 0.0);
});

test('Cubic transformInternal throws for NaN', () {
expect(() => Curves.easeOut.transformInternal(double.nan), throwsArgumentError);
});
Comment thread
gabrimatic marked this conversation as resolved.

test('Invalid transform parameter should assert', () {
expect(() => const SawTooth(2).transform(-0.0001), throwsAssertionError);
expect(() => const SawTooth(2).transform(1.0001), throwsAssertionError);
Expand Down
Loading