转换小部件后 OnPressed 在 Stack 小部件内不起作用

a2e*_*2en 8 flutter

在给定的代码中,onPressed 在凸起的按钮上起作用并将 FlatButton 转换到顶部。但是 FlatButton 上的 onPressed 不起作用

@override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Transform(
          transform: Matrix4.translationValues(
            0.0,
            _translateButton.value,
            0.0,
          ),
          child: FlatButton(
            onPressed: () {
              print('tapped Flat button');
            },
            child: Text('upper'),
          ),
        ),
          RaisedButton(
            onPressed: () {
              animate();
              print('tapped Raised button');
            },
            child: Text('lower'))
      ],
    );
  }
Run Code Online (Sandbox Code Playgroud)

当 animate() 被调用时,这里 _translatebutton 值从 0 变为 -60

 _animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 500))
      ..addListener(() {
        setState(() {});
      });
    _translateButton = Tween<double>(
      begin: 0,
      end: -60,
    ).animate(CurvedAnimation(
      parent: _animationController,
      curve: Interval(
        0.0,
        0.75,
        curve: _curve,
      ),
    ));
Run Code Online (Sandbox Code Playgroud)

vzu*_*urd 1

将 Transform 小部件包装在 SizedBox 中(展开或缩小尺寸,具体取决于您的要求。