gpt4 book ai didi

animation - 容器高度动画从中间开始

转载 作者:IT王子 更新时间:2023-10-29 07:06:47 27 4
gpt4 key购买 nike

Flutter Container 高度动画从中间开始,但我需要它从底部开始这里是我的代码

import 'dart:math';
import 'package:flutter/material.dart';

class CorrectWrongOverlay extends StatefulWidget {
final bool _isCorrect;
final VoidCallback _onTap;
final double percentR;
final double percentW;

CorrectWrongOverlay(
this._isCorrect, this.percentR, this.percentW, this._onTap);

@override
State createState() => CorrectWrongOverlayState();
}

class CorrectWrongOverlayState extends State<CorrectWrongOverlay>
with SingleTickerProviderStateMixin {
Animation<double> _iconAnimation;
AnimationController _iconAnimationController;

@override
void initState() {
super.initState();
_iconAnimationController = AnimationController(
duration: Duration(seconds: 3), vsync: this);
_iconAnimation = CurvedAnimation(
parent: _iconAnimationController, curve: Curves.fastOutSlowIn);
_iconAnimation.addListener(() => this.setState(() {}));
_iconAnimationController.forward();
}

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

@override
Widget build(BuildContext context) {
return Material(
color: Colors.black54,
child: InkWell(
onTap: () => widget._onTap(),
child: Padding(
padding: const EdgeInsets.all(18.0),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 80.0,
height: 200.0 * _iconAnimation.value,
color: Colors.green,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 80.0,
height: 200.0,
color: Colors.green,
),
)
],
),
),
),
),
);
}
}

我正在尝试在 Flutter 中实现这种带有高度增长动画的 UI 我希望动画从底部开始,但它从容器的中心开始并在两侧设置动画。

Please take a look at the Image

最佳答案

从特定点开始缩放动画。您可以使用 Align 小部件包装您的 Container 并简单地指定某些起始位置。

定义你的 Controller 和动画变量;

  AnimationController animationController;
Animation<double> tween;

在initState方法中初始化它们;

   @override
void initState() {
super.initState();
animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 800));
tween = Tween<double>(begin:0,end:1).animate(CurvedAnimation(parent: animationController, curve: Curves.easeIn));
animationController.addListener(() {
setState(() {});
});
}

然后在 build 方法中或者你添加的地方使用 return Widget,如下所示;

Widget animatedContainer(){
return Align(
alignment: Alignment.topRight,// .topCenter, .topLeft, .bottomLeft, bottomCenter...etc
child: Container(
width: (size.width * tween.value).abs(),
height: (200 *tween.value).abs(),
color:Colors.red
),
);
}

关于animation - 容器高度动画从中间开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50227649/

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