Rafal
Rafal

Reputation: 105

CurvedAnimation dosen't respect Curve type

Forwarding animation controller always results in linear change of controller's value. It dosen't depend on CurvedAnimation's curve parameter. Changing Curve type dosen't help either. Also, I tried changing duration to 40 seconds, but it was still linear output. Curve parameter dosen't change anything, it is still same output for all different curve types.

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp>
    with SingleTickerProviderStateMixin {
  AnimationController animationController;

  @override
  void initState() {
    super.initState();
    animationController =
        AnimationController(vsync: this, duration: Duration(milliseconds: 300));
    CurvedAnimation(parent: animationController, curve: Curves.bounceIn)
        .addListener(() {
      print(animationController.value);
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: GestureDetector(
            onTap: () {
              animationController.forward(from: 0.0);
            },
            child: Center(
              child: Container(
                child: Text("forward from 0.0"),
              ),
            )),
      ),
    );
  }
}

Output is always linear. Output after button is pressed:

I/flutter (19637): 0.0
I/flutter (19637): 0.0
I/flutter (19637): 0.05566000000000001
I/flutter (19637): 0.11121666666666667
I/flutter (19637): 0.16677333333333333
I/flutter (19637): 0.22233
I/flutter (19637): 0.27788666666666667
I/flutter (19637): 0.3340766666666667
I/flutter (19637): 0.3897666666666667
I/flutter (19637): 0.4454566666666667
I/flutter (19637): 0.5011433333333334
I/flutter (19637): 0.5568333333333334
I/flutter (19637): 0.6125233333333334
I/flutter (19637): 0.6682133333333333
I/flutter (19637): 0.7239033333333333
I/flutter (19637): 0.7795933333333334
I/flutter (19637): 0.8352799999999999
I/flutter (19637): 0.89097
I/flutter (19637): 0.94666
I/flutter (19637): 1.0

Upvotes: 0

Views: 256

Answers (1)

Richard Heap
Richard Heap

Reputation: 51692

You need to print the value of the CurvedAnimation.

  @override
  void initState() {
    super.initState();
    animationController =
        AnimationController(vsync: this, duration: Duration(milliseconds: 300));
    CurvedAnimation ca =
        CurvedAnimation(parent: animationController, curve: Curves.bounceIn);
    ca.addListener(() => print(ca.value));
  }

Upvotes: 1

Related Questions