release 1.0.0

master
Jpeng 5 years ago
parent 3abbcaae71
commit 3b1c3a4065

@ -1,3 +1,6 @@
## [0.0.1] - TODO: Add release date.
* TODO: Describe initial release.
## 1.0.0
* init release

@ -1 +1,21 @@
TODO: Add your license here.
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.

@ -1,14 +1,49 @@
# flutter_gifimage
A new Flutter package project.
We should know that in order to achieve Gif in flutter, we can use Image, but we have no way to manipulate Gif, for example: change its speed, control it has been playing in a frame,
in which frame range loop. These problems can be solved by this control.
## Getting Started
* Usage(Simple)
This project is a starting point for a Dart
[package](https://flutter.dev/developing-packages/),
a library module containing code that can be shared easily across
multiple Flutter or Dart projects.
```dart
controller4= GifController(vsync: this);
For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
GifImage(
controller: controller,
image: MemoryImage(base64Decode(base64_url)),
)
```
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 = .. '
# Thanks
* [gif_ani](https://github.com/hyz1992/gif_ani) (thanks for giving me idea)
# License
```
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.
```

@ -99,59 +99,7 @@ class GifImageState extends State<GifImage>{
return _infos==null?null:_infos[_curIndex];
}
static final HttpClient _sharedHttpClient = HttpClient()..autoUncompress = false;
static HttpClient get _httpClient {
HttpClient client = _sharedHttpClient;
assert(() {
if (debugNetworkImageHttpClientProvider != null)
client = debugNetworkImageHttpClientProvider();
return true;
}());
return client;
}
Future<void> _fetchImage() async{
ImageProvider provider = widget.image;
dynamic data;
String key =provider is NetworkImage?provider.url:provider is AssetImage?provider.assetName:provider is MemoryImage?provider.bytes.toString():"";
if(GifImage.cache.caches.containsKey(key)){
_infos = GifImage.cache.caches[key];
return ;
}
if(provider is NetworkImage){
final Uri resolved = Uri.base.resolve(provider.url);
final HttpClientRequest request = await _httpClient.getUrl(resolved);
provider.headers?.forEach((String name, String value) {
request.headers.add(name, value);
});
final HttpClientResponse response = await request.close();
data = await consolidateHttpClientResponseBytes(
response,
);
}
else if(provider is AssetImage){
AssetBundleImageKey key = await provider.obtainKey(ImageConfiguration());
data = await key.bundle.load(key.name);
}
else if(provider is FileImage){
data = await provider.file.readAsBytes();
}
else if(provider is MemoryImage){
data = provider.bytes;
}
ui.Codec codec=await PaintingBinding.instance.instantiateImageCodec(data.buffer.asUint8List());
_infos = [];
for(int i = 0;i<codec.frameCount;i++){
FrameInfo frameInfo = await codec.getNextFrame();
//scale ??
_infos.add(ImageInfo(image: frameInfo.image));
}
GifImage.cache.caches.putIfAbsent(key, () => _infos);
}
@override
void initState() {
@ -169,8 +117,9 @@ class GifImageState extends State<GifImage>{
void didUpdateWidget(GifImage oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.image != oldWidget.image) {
_fetchImage().then((_){
fetchGif(widget.image).then((imageInfors){
setState(() {
_infos = imageInfors;
_fetchComplete=true;
_curIndex = widget.controller.value.toInt();
if(widget.onFetchCompleted!=null){
@ -197,8 +146,9 @@ class GifImageState extends State<GifImage>{
void didChangeDependencies() {
super.didChangeDependencies();
if(_infos==null){
_fetchImage().then((_){
fetchGif(widget.image).then((imageInfors){
setState(() {
_infos = imageInfors;
_fetchComplete=true;
_curIndex = widget.controller.value.toInt();
if(widget.onFetchCompleted!=null){
@ -234,3 +184,59 @@ class GifImageState extends State<GifImage>{
);
}
}
final HttpClient _sharedHttpClient = HttpClient()..autoUncompress = false;
HttpClient get _httpClient {
HttpClient client = _sharedHttpClient;
assert(() {
if (debugNetworkImageHttpClientProvider != null)
client = debugNetworkImageHttpClientProvider();
return true;
}());
return client;
}
Future<List<ImageInfo>> fetchGif(ImageProvider provider) async{
List<ImageInfo> infos = [];
dynamic data;
String key =provider is NetworkImage?provider.url:provider is AssetImage?provider.assetName:provider is MemoryImage?provider.bytes.toString():"";
if(GifImage.cache.caches.containsKey(key)){
infos = GifImage.cache.caches[key];
return infos;
}
if(provider is NetworkImage){
final Uri resolved = Uri.base.resolve(provider.url);
final HttpClientRequest request = await _httpClient.getUrl(resolved);
provider.headers?.forEach((String name, String value) {
request.headers.add(name, value);
});
final HttpClientResponse response = await request.close();
data = await consolidateHttpClientResponseBytes(
response,
);
}
else if(provider is AssetImage){
AssetBundleImageKey key = await provider.obtainKey(ImageConfiguration());
data = await key.bundle.load(key.name);
}
else if(provider is FileImage){
data = await provider.file.readAsBytes();
}
else if(provider is MemoryImage){
data = provider.bytes;
}
ui.Codec codec=await PaintingBinding.instance.instantiateImageCodec(data.buffer.asUint8List());
infos = [];
for(int i = 0;i<codec.frameCount;i++){
FrameInfo frameInfo = await codec.getNextFrame();
//scale ??
infos.add(ImageInfo(image: frameInfo.image));
}
GifImage.cache.caches.putIfAbsent(key, () => infos);
return infos;
}

@ -1,27 +1,6 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.2"
collection:
dependency: transitive
description:
@ -34,18 +13,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.5"
meta:
dependency: transitive
description:
@ -53,74 +20,11 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.6"
path:
dependency: transitive
description:
name: path
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.6.2"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.3"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.5.5"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.3"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.5"
typed_data:
dependency: transitive
description:

@ -1,8 +1,8 @@
name: flutter_gifimage
description: A new Flutter package project.
description: a gifimage for flutter,for solving gif cannot be controlled speed,progress
version: 1.0.0
author:
homepage:
author: Jpeng <peng8350@gmail.com>
homepage: https://github.com/peng8350/flutter_gifimage
environment:
sdk: ">=2.1.0 <3.0.0"

Loading…
Cancel
Save