gpt4 book ai didi

dart - 为 flutter 小部件的高度设置动画

转载 作者:IT王子 更新时间:2023-10-29 06:48:45 25 4
gpt4 key购买 nike

我想在没有两只手的情况下为小部件的高度设置动画(:

我试过更改 Material 小部件的高度但没有任何改变

enter image description here

最佳答案

要为海拔设置动画,您需要使用 AnimationController 自行处理动画。这是一个完整的例子:

import 'package:flutter/material.dart';

void main() => runApp(App());

class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: AnimatedElevationButton(),
),
),
);
}
}

class AnimatedElevationButton extends StatefulWidget {
@override
_AnimatedElevationButtonState createState() =>
_AnimatedElevationButtonState();
}

class _AnimatedElevationButtonState extends State<AnimatedElevationButton>
with SingleTickerProviderStateMixin {
AnimationController _animationController;
Animation<double> _animationTween;

@override
void initState() {
super.initState();

_animationController = AnimationController(
duration: Duration(milliseconds: 30),
vsync: this,
);
_animationTween =
Tween(begin: 20.0, end: 0.0).animate(_animationController);
_animationController.addListener(() {
setState(() {});
});
}

@override
Widget build(BuildContext context) {
return GestureDetector(
onTapDown: _onTapDown,
onTapUp: _onTapUp,
child: Material(
color: Colors.red,
borderRadius: BorderRadius.circular(8.0),
elevation: _animationTween.value,
child: SizedBox(
width: 100,
height: 50,
),
),
);
}

void _onTapDown(TapDownDetails details) {
_animationController.forward();
}

void _onTapUp(TapUpDetails details) {
_animationController.reverse();
}
}

关于dart - 为 flutter 小部件的高度设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55376611/

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