| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import 'package:flutter/material.dart';
- // ignore: must_be_immutable
- class FrameAnimationImage extends StatefulWidget {
- List<String> assetList;
- double width,height;
- int interval = 200;
- FrameAnimationImage({ Key? key,required this.assetList,required this.width,required this.height, required this.interval }) : super(key: key);
- @override
- State<FrameAnimationImage> createState() => _FrameAnimationImageState();
- }
- class _FrameAnimationImageState extends State<FrameAnimationImage> with SingleTickerProviderStateMixin{
- late Animation animation;
- late AnimationController controller;
- @override
- void initState() {
- int imageCount = widget.assetList.length;
- int maxTime = widget.interval*imageCount;
- controller = AnimationController(vsync: this,duration: Duration(milliseconds: maxTime));
- controller.addListener(() {
- setState(() {
-
- });
- });
- animation = Tween(begin: 0.0,end: imageCount.toDouble()).animate(controller)..addListener(() {setState(() {
-
- });});
- controller.repeat();
- super.initState();
- }
- @override
- void dispose() {
- controller.dispose();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- int ix = animation.value.floor()%widget.assetList.length;
- List<Widget> images = [];
- for (int i=0;i<widget.assetList.length;i++){
- if (i!=ix){
- images.add(Image.asset(widget.assetList[i],width: 0,height: 0,));
- }
- }
- images.add(Image.asset(widget.assetList[ix],width: widget.width,height: widget.height,));
- return Stack (
- alignment: Alignment.center,
- children: images,
- );
- }
- }
|