我遇到了一个非常奇怪的问题。这就像某种类型的混乱?
如果我像这样编写动画,它会按预期工作:
Widget _animatedButtonsBuilder(BuildContext context,LoginState state)…
我认为要获得相同的结果,您需要将该行移动到构建器中, 因为每次动画进行时都会执行它,而不仅仅是在动画开始时。
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: () {}, )); }); }