CurvedAnimation不尊重曲线类型

时间:2018-12-27 18:38:02

标签: animation dart flutter

前向动画控制器始终会导致控制器值线性变化。它不依赖于CurvedAnimation的curve参数。 更改“曲线”类型也无济于事。另外,我尝试将持续时间更改为40秒,但仍然是线性输出。曲线参数没有任何变化,对于所有不同的曲线类型,它仍然是相同的输出。

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"),
              ),
            )),
      ),
    );
  }
}

输出始终是线性的。按下按钮后的输出:

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

1 个答案:

答案 0 :(得分:1)

您需要打印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));
  }