gpt4 book ai didi

dart - Matrix4 参数在间接传递给 Transform 时表现不同

转载 作者:IT老高 更新时间:2023-10-28 12:46:44 25 4
gpt4 key购买 nike

我遇到了一个非常奇怪的问题。这就像某种类型的混淆?

如果我这样写我的动画,它会按预期工作:

Widget _animatedButtonsBuilder(BuildContext context, LoginState state) {
final animTarget = state.isPhoneNumberFocused
? _controller.lowerBound
: _controller.upperBound;

_controller.animateTo(animTarget);

final double width = MediaQuery.of(context).size.width;
//final transform = Matrix4.translationValues(_animation.value * width, 0.0, 0.0)..scale(1.0, 1.0-_animation.value, 1.0);

return AnimatedBuilder(
animation: _controller,
builder: (BuildContext context, Widget child) {
return Transform(
transform: Matrix4.translationValues(_animation.value * width, 0.0, 0.0)..scale(1.0, 1.0-_animation.value, 1.0),
child: new RaisedButton(
child: const Text('Login'),
color: Color(0xff938065),
elevation: 4.0,
splashColor: Colors.blueGrey,
textColor: Color(0xffffffff),
onPressed: () {},
));
});
}

但是如果我取消注释

//final transform = Matrix4.transla...

并将其传递给 transform: 参数,它似乎无法正常工作。

这是怎么回事?

最佳答案

我认为要获得相同的结果,您需要将该行移至生成器中,因为它会在每次动画进行时执行,而不仅仅是在动画开始时执行。

Widget _animatedButtonsBuilder(BuildContext context, LoginState state) {
final animTarget = state.isPhoneNumberFocused
? _controller.lowerBound
: _controller.upperBound;

_controller.animateTo(animTarget);

final double width = MediaQuery.of(context).size.width;

return AnimatedBuilder(
animation: _controller,
builder: (BuildContext context, Widget child) {
//final transform = Matrix4.translationValues(_animation.value * width, 0.0, 0.0)..scale(1.0, 1.0-_animation.value, 1.0);

return Transform(
transform: Matrix4.translationValues(_animation.value * width, 0.0, 0.0)..scale(1.0, 1.0-_animation.value, 1.0),
child: new RaisedButton(
child: const Text('Login'),
color: Color(0xff938065),
elevation: 4.0,
splashColor: Colors.blueGrey,
textColor: Color(0xffffffff),
onPressed: () {},
));
});
}

关于dart - Matrix4 参数在间接传递给 Transform 时表现不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54996791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com