我最近正在研究類似SlideTransition顫動的影片。我想做的是從螢屏頁面的中心顯示一個影像,然后在 3 秒后我想讓影像從中心向上移動幾厘米。有沒有辦法做到這一點 ?
uj5u.com熱心網友回復:
請查看以下代碼:
import 'package:flutter/material.dart';
class TransitionUpAnimation extends StatefulWidget {
const TransitionUpAnimation({Key? key}) : super(key: key);
@override
State<TransitionUpAnimation> createState() => _TransitionUpAnimationState();
}
class _TransitionUpAnimationState extends State<TransitionUpAnimation>
with TickerProviderStateMixin {
AnimationController? _controller;
Animation<Offset>? _animation;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 1),
vsync: this,
);
_animation = Tween<Offset>(
begin: const Offset(0.0, 0.0),
end: const Offset(0.0, -2),
).animate(CurvedAnimation(
parent: _controller!,
curve: Curves.easeInCubic,
));
Future.delayed(const Duration(milliseconds: 3000), () {
_controller!.forward();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SlideTransition(
position: _animation!,
child: Container(
width: 100,
height: 100,
color: Colors.red,
),
),
),
);
}
}
輸出:

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/409751.html
標籤:
下一篇:LSTM模型輸出的奇怪行為
