From 32547e86421b6a49ab592901d2b051ac5004d874 Mon Sep 17 00:00:00 2001 From: Jpeng Date: Thu, 1 Aug 2019 19:36:04 +0800 Subject: [PATCH] update readme --- README.md | 41 +++++++++++++++++++++++++++++++++++---- lib/flutter_gifimage.dart | 11 +++++++++-- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 433bc8e..d89ec67 100644 --- a/README.md +++ b/README.md @@ -8,19 +8,52 @@ We should know that in order to achieve Gif in flutter, we can use Image, but we ![](arts/gif.gif) # Usage(Simple) + add in pubspec + + ```dart + + flutter_gifimage: ^1.0.0 + + ``` + + simple usage ```dart - controller4= GifController(vsync: this); + GifController controller= GifController(vsync: this); GifImage( controller: controller, - image: MemoryImage(base64Decode(base64_url)), + image: AssetImage("images/animate.gif"), ) ``` - GifController is just a AnimationController, usage is the same with AnimationController,If you want to play animate Between two frames ,you just called 'repeat(min: max:)','period' can change the repeat speed - ,If you want to stop in one frame , call 'controller.value = .. ' + + list the most common operate in GifController: + + + ```dart + // loop from 0 frame to 29 frame + controller.repeat(min:0,max:29,period:Duration(millseconds:300)); + + // jumpTo thrid frame(index from 0) + controller.value = 0; + + // from current frame to 26 frame + controller.animateTo(26); + + ``` + + If you need to preCache gif,try this + + ```dart + // put imageProvider + fetchGif(AssetImage("images/animate.gif")); + + ``` + + + # Thanks * [gif_ani](https://github.com/hyz1992/gif_ani) (thanks for giving me idea) diff --git a/lib/flutter_gifimage.dart b/lib/flutter_gifimage.dart index 78b8fd4..73c7672 100644 --- a/lib/flutter_gifimage.dart +++ b/lib/flutter_gifimage.dart @@ -13,10 +13,10 @@ import 'dart:ui'; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; +/// cache gif fetched image class GifCache{ final Map> caches= Map(); - void clear() { caches.clear(); } @@ -28,8 +28,8 @@ class GifCache{ } return false; } - } + /// controll gif class GifController extends AnimationController{ @@ -46,8 +46,15 @@ class GifController extends AnimationController{ animationBehavior:animationBehavior??AnimationBehavior.normal, vsync:vsync); + @override + void reset() { + // TODO: implement reset + value = 0.0; + } + } + class GifImage extends StatefulWidget{ GifImage({ @required this.image,