flutter_gif
为了在 Flutter 中实现 Gif,我们可以使用 Image,但我们无法操作 Gif,例如:改变它的速度,控制它是否在某一帧播放,以及在哪个帧范围内循环。这个 widget 可以解决这些问题,它还可以帮助你包含 gif 缓存,避免每次加载帧。
截图
用法(简单)
在 pubspec 中添加
flutter_gif: ^1.0.0
简单用法
FlutterGifController controller= FlutterGifController(vsync: this);
GifImage(
controller: controller,
image: AssetImage("images/animate.gif"),
)
列出 FlutterGifController 中最常用的操作
// loop from 0 frame to 29 frame
controller.repeat(min:0, max:29, period:const Duration(millseconds:300));
// jumpTo thrid frame(index from 0)
controller.value = 0;
// from current frame to 26 frame
controller.animateTo(26);
如果你需要预缓存 gif,请尝试这个
// put imageProvider
fetchGif(AssetImage("images/animate.gif"));
感谢
许可证
MIT License
Copyright (c) 2019 Jpeng
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
