flutter - 单击子小部件中存在的按钮时,如何更改父小部件的动画?

标签 flutter dart

我是新手,这是我尝试构建的第一个应用程序。
该应用程序是抽认卡应用程序,用户可以在其中制作自定义抽认卡。
我试图在子窗口小部件上按下按钮时更改父窗口小部件的动画。
图解上我想要类似的东西
enter image description here
前两个部分已经完成,但是自动旋转180度(第三个图)是我无法确定的。
以下是我的父窗口小部件:

class CardController extends StatefulWidget {
  CardControllerState createState() => new CardControllerState();
}

class CardControllerState extends State<CardController>
    with TickerProviderStateMixin {
  AnimationController _controller;
  Animation<double> _frontScale;
  Animation<double> _backScale;
  Animation<Offset> _offsetAnimation;
  double _opacity = 1;

  @override
  void initState() {
    super.initState();
    _controller = new AnimationController(
      vsync: this,
      duration: const Duration(seconds: 1),
    );
    _frontScale = new Tween(
      begin: 1.0,
      end: 0.0,
    ).animate(new CurvedAnimation(
      parent: _controller,
      curve: new Interval(0.0, 0.5, curve: Curves.easeIn),
    ));
    _backScale = new CurvedAnimation(
      parent: _controller,
      curve: new Interval(0.5, 1.0, curve: Curves.easeOut),
    );
    _offsetAnimation = Tween<Offset>(
      begin: Offset.zero,
      end: const Offset(1.5, 0.0),
    ).animate(CurvedAnimation(
      parent: _controller,
      curve: Curves.elasticIn,
    ));
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(),
        body: Container(
            child: AnimatedOpacity(
          opacity: _opacity,
          duration: Duration(seconds: 1),
          child: GestureDetector(
            onTap: () {
              setState(() {
                if (_controller.isCompleted || _controller.velocity > 0)
                  _controller.reverse();
                else
                  _controller.forward();
              });
            },
            child: new Column(children: <Widget>[
              new Stack(alignment: Alignment.center, children: <Widget>[
                CardFolding(_backScale),
                CardFoldingBack(_frontScale)
              ]),
              RaisedButton(
                  onPressed: () {
                    setState(() {
                      _opacity = 0;
                    });
                  },
                  child: Text('Add New Card'))
            ]),
          ),
        )));
  }
}
CardFolding类包含以下代码:
AnimatedBuilder(
      child: new CardWidget(colors: Colors.orange),
      animation: backScale,
      builder: (BuildContext context, Widget child) {
        final Matrix4 transform = new Matrix4.identity()
          ..scale(1.0, backScale.value, 1.0);
        return new Transform(
          transform: transform,
          alignment: FractionalOffset.center,
          child: child,
        );
      },
    );
CardWidget包含以下代码:
Container(
      alignment: FractionalOffset.center,
      height: 144.0,
      width: 360.0,
      decoration: new BoxDecoration(
        color: colors.shade50,
        border: new Border.all(color: new Color(0xFF9E9E9E)),
      ),
      child: Form(
        key: _formKey,
        child: Column(
          children: <Widget>[
            _buildQuestion(),
            RaisedButton(
              child: Text(
                'Submit',
                style: TextStyle(color: Colors.blue, fontSize: 16),
              ),
              onPressed: () {
                if (!_formKey.currentState.validate()) {
                  return;
                }
                _formKey.currentState.save();
                print(_question);
              },
            ),
          ],
        ),
      ),
    );
感谢您的帮助!!

最佳答案

用NotificationListener包裹CardFolding,然后按Submit调度Notification并从Animation中控制onNotificationhttps://www.youtube.com/watch?v=cAnFbFoGM50

关于flutter - 单击子小部件中存在的按钮时,如何更改父小部件的动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64006594/

相关文章:

visual-studio - 如何 "Import in flutterTest Widget"

flutter - List.map()中的递增计数

dart - 将 header 添加到SecureSocket或将SecurityContext添加到WebSpcket

xcode - Flutters video_editor 示例的 Pod 安装失败

flutter - 名称 'string'不是类型,不能在 'is'表达式中使用

flutter - “该表达式的类型为 'void',因此无法使用其值。” Flutter 中的 setState() 错误

dart - 打开 HttpRequest 时,我收到此错误 : 2 positional arguments expected, 但发现 5

flutter - Column/SingleChildScrollView 不滚动

dart - 偏移量是不同的 onTap 和 OnDrag - Flutter

flutter - 当特定条件为真时,如何在抖动中显示进度指示器?