日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Flutter 使用动画播放一组图片

發布時間:2025/3/8 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Flutter 使用动画播放一组图片 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

請支持原文:tryenough.com/images-anim…

效果如下圖:

代碼

import 'package:flutter/material.dart'; import 'package:sprintf/sprintf.dart'; //這個是一個拼接字符串的flutter庫,主要是為了使用方便,你可以選擇不使用,這樣的話你需要自己拼接圖片路徑class ImagesAnimation extends StatefulWidget {final double w;final double h;final ImagesAnimationEntry entry;final int durationSeconds;ImagesAnimation({Key key, this.w : 80, this.h : 80, this.entry, this.durationSeconds : 3}):super(key:key);@override_InState createState() {return _InState();} }class _InState extends State<ImagesAnimation> with TickerProviderStateMixin{AnimationController _controller;Animation<int> _animation;@overridevoid initState() {super.initState();_controller = new AnimationController(vsync: this, duration: Duration(seconds: widget.durationSeconds))..repeat();_animation = new IntTween(begin: widget.entry.lowIndex, end: widget.entry.highIndex).animate(_controller); //widget.entry.lowIndex 表示從第幾下標開始,如0;widget.entry.highIndex表示最大下標:如7}@overrideWidget build(BuildContext context) {return new AnimatedBuilder(animation: _animation,builder: (BuildContext context, Widget child) {String frame = _animation.value.toString();return new Image.asset(sprintf(widget.entry.basePath, [frame]), //根據傳進來的參數拼接路徑gaplessPlayback: true, //避免圖片閃爍width: widget.w,height: widget.h,);},);}}class ImagesAnimationEntry {int lowIndex = 0;int highIndex = 0;String basePath;ImagesAnimationEntry(this.lowIndex, this.highIndex, this.basePath); } 復制代碼

請支持原文:tryenough.com/images-anim…

使用的地方:

ImagesAnimation(w: 100, h: 100, entry: ImagesAnimationEntry(1, 7, "images/men_sport_%s.png")), //"images/men_sport_%s.png" 表示圖片在你本地的路徑,%s會被下標代替 復制代碼

轉載于:https://juejin.im/post/5cbee0f551882567d43769d8

總結

以上是生活随笔為你收集整理的Flutter 使用动画播放一组图片的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。