diff --git a/CHANGELOG.md b/CHANGELOG.md index b639ede..4a18dca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,3 +4,6 @@ ## 1.0.0 * init release + +## 1.0.1 +* add check mounted when setState diff --git a/example/pubspec.lock b/example/pubspec.lock index c3b4a17..9b9a4ec 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,14 +7,14 @@ packages: name: async url: "https://pub.flutter-io.cn" source: hosted - version: "2.2.0" + version: "2.3.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.4" + version: "1.0.5" charcode: dependency: transitive description: @@ -47,7 +47,7 @@ packages: path: ".." relative: true source: path - version: "1.0.0" + version: "1.0.1" flutter_test: dependency: "direct dev" description: flutter @@ -66,28 +66,28 @@ packages: name: meta url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.6" + version: "1.1.7" path: dependency: transitive description: name: path url: "https://pub.flutter-io.cn" source: hosted - version: "1.6.2" + version: "1.6.4" pedantic: dependency: transitive description: name: pedantic url: "https://pub.flutter-io.cn" source: hosted - version: "1.7.0" + version: "1.8.0+1" quiver: dependency: transitive description: name: quiver url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.3" + version: "2.0.5" sky_engine: dependency: transitive description: flutter @@ -120,7 +120,7 @@ packages: name: string_scanner url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.4" + version: "1.0.5" term_glyph: dependency: transitive description: diff --git a/lib/flutter_gifimage.dart b/lib/flutter_gifimage.dart index 73c7672..4fefcf0 100644 --- a/lib/flutter_gifimage.dart +++ b/lib/flutter_gifimage.dart @@ -102,7 +102,7 @@ class GifImageState extends State{ int _curIndex = 0; bool _fetchComplete= false; ImageInfo get _imageInfo { - if(!_fetchComplete)return null; + if(!_fetchComplete)return null; return _infos==null?null:_infos[_curIndex]; } @@ -125,14 +125,15 @@ class GifImageState extends State{ super.didUpdateWidget(oldWidget); if (widget.image != oldWidget.image) { fetchGif(widget.image).then((imageInfors){ - setState(() { - _infos = imageInfors; - _fetchComplete=true; - _curIndex = widget.controller.value.toInt(); - if(widget.onFetchCompleted!=null){ - widget.onFetchCompleted(); - } - }); + if(mounted) + setState(() { + _infos = imageInfors; + _fetchComplete=true; + _curIndex = widget.controller.value.toInt(); + if(widget.onFetchCompleted!=null){ + widget.onFetchCompleted(); + } + }); }); } if (widget.controller != oldWidget.controller) { @@ -143,9 +144,10 @@ class GifImageState extends State{ void _listener(){ if(_curIndex!=widget.controller.value&&_fetchComplete){ - setState(() { - _curIndex = widget.controller.value.toInt(); - }); + if(mounted) + setState(() { + _curIndex = widget.controller.value.toInt(); + }); } } @@ -154,14 +156,15 @@ class GifImageState extends State{ super.didChangeDependencies(); if(_infos==null){ fetchGif(widget.image).then((imageInfors){ - setState(() { - _infos = imageInfors; - _fetchComplete=true; - _curIndex = widget.controller.value.toInt(); - if(widget.onFetchCompleted!=null){ - widget.onFetchCompleted(); - } - }); + if(mounted) + setState(() { + _infos = imageInfors; + _fetchComplete=true; + _curIndex = widget.controller.value.toInt(); + if(widget.onFetchCompleted!=null){ + widget.onFetchCompleted(); + } + }); }); } } diff --git a/pubspec.lock b/pubspec.lock index d6986e0..a801c8e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -19,7 +19,7 @@ packages: name: meta url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.6" + version: "1.1.7" sky_engine: dependency: transitive description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index 5b599f1..fd2a933 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_gifimage description: a gifimage for flutter,for solving gif cannot be controlled speed,progress -version: 1.0.0 +version: 1.0.1 author: Jpeng homepage: https://github.com/peng8350/flutter_gifimage