update readme

master
Jpeng 5 years ago
parent efbecf7b7d
commit 32547e8642

@ -8,19 +8,52 @@ We should know that in order to achieve Gif in flutter, we can use Image, but we
![](arts/gif.gif) ![](arts/gif.gif)
# Usage(Simple) # Usage(Simple)
add in pubspec
```dart ```dart
controller4= GifController(vsync: this);
flutter_gifimage: ^1.0.0
```
simple usage
```dart
GifController controller= GifController(vsync: this);
GifImage( GifImage(
controller: controller, 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 # Thanks
* [gif_ani](https://github.com/hyz1992/gif_ani) (thanks for giving me idea) * [gif_ani](https://github.com/hyz1992/gif_ani) (thanks for giving me idea)

@ -13,10 +13,10 @@ import 'dart:ui';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
/// cache gif fetched image
class GifCache{ class GifCache{
final Map<String,List<ImageInfo>> caches= Map(); final Map<String,List<ImageInfo>> caches= Map();
void clear() { void clear() {
caches.clear(); caches.clear();
} }
@ -28,8 +28,8 @@ class GifCache{
} }
return false; return false;
} }
} }
/// controll gif /// controll gif
class GifController extends AnimationController{ class GifController extends AnimationController{
@ -46,8 +46,15 @@ class GifController extends AnimationController{
animationBehavior:animationBehavior??AnimationBehavior.normal, animationBehavior:animationBehavior??AnimationBehavior.normal,
vsync:vsync); vsync:vsync);
@override
void reset() {
// TODO: implement reset
value = 0.0;
}
} }
class GifImage extends StatefulWidget{ class GifImage extends StatefulWidget{
GifImage({ GifImage({
@required this.image, @required this.image,

Loading…
Cancel
Save