Refactor ZoomableImage

This commit is contained in:
Vishnu Mohandas 2020-06-17 18:08:18 +05:30
parent e145358a84
commit 456f30738c

View file

@ -1,6 +1,6 @@
import 'package:extended_image/extended_image.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:logging/logging.dart';
import 'package:photos/core/cache/image_cache.dart';
import 'package:photos/core/cache/thumbnail_cache.dart';
import 'package:photos/models/photo.dart';
@ -24,6 +24,7 @@ class ZoomableImage extends StatefulWidget {
class _ZoomableImageState extends State<ZoomableImage>
with SingleTickerProviderStateMixin {
final Logger _logger = Logger("ZoomableImage");
ImageProvider _imageProvider;
bool _loadedSmallThumbnail = false;
bool _loadingLargeThumbnail = false;
@ -31,9 +32,6 @@ class _ZoomableImageState extends State<ZoomableImage>
bool _loadingFinalImage = false;
bool _loadedFinalImage = false;
ValueChanged<PhotoViewScaleState> _scaleStateChangedCallback;
// AnimationController _animationController;
// Animation _animation;
// VoidCallback _animationListener;
final doubleTapScales = [1.0, 2.0];
@override
@ -43,10 +41,6 @@ class _ZoomableImageState extends State<ZoomableImage>
widget.shouldDisableScroll(value != PhotoViewScaleState.initial);
}
};
// _animationController = AnimationController(
// vsync: this,
// duration: const Duration(milliseconds: 100),
// );
super.initState();
}
@ -59,41 +53,6 @@ class _ZoomableImageState extends State<ZoomableImage>
}
if (_imageProvider != null) {
// return ExtendedImage(
// image: _imageProvider,
// gaplessPlayback: true,
// mode: ExtendedImageMode.gesture,
// enableSlideOutPage: true,
// initGestureConfigHandler: (state) {
// return GestureConfig(
// inPageView: true,
// initialScale: 1.0,
// minScale: 1.0,
// );
// },
// onDoubleTap: (ExtendedImageGestureState state) {
// var pointerDownPosition = state.pointerDownPosition;
// double begin = state.gestureDetails.totalScale;
// double end;
// _animation?.removeListener(_animationListener);
// _animationController.stop();
// _animationController.reset();
// if (begin == doubleTapScales[0]) {
// end = doubleTapScales[1];
// } else {
// end = doubleTapScales[0];
// }
// _animationListener = () {
// state.handleDoubleTap(
// scale: _animation.value,
// doubleTapPosition: pointerDownPosition);
// };
// _animation =
// _animationController.drive(Tween<double>(begin: begin, end: end));
// _animation.addListener(_animationListener);
// _animationController.forward();
// },
// );
return PhotoView(
imageProvider: _imageProvider,
scaleStateChangedCallback: _scaleStateChangedCallback,
@ -174,14 +133,12 @@ class _ZoomableImageState extends State<ZoomableImage>
_loadingFinalImage = true;
final cachedFile = FileLruCache.get(widget.photo);
if (cachedFile != null) {
final imageProvider = Image.file(cachedFile).image;
_onFinalImageLoaded(imageProvider, context);
_onFinalImageLoaded(Image.file(cachedFile).image, context);
} else {
widget.photo.getAsset().then((asset) {
asset.file.then((file) {
if (mounted) {
final imageProvider = Image.file(file).image;
_onFinalImageLoaded(imageProvider, context);
_onFinalImageLoaded(Image.file(file).image, context);
FileLruCache.put(widget.photo, file);
}
});
@ -194,7 +151,7 @@ class _ZoomableImageState extends State<ZoomableImage>
ImageProvider imageProvider, BuildContext context) {
if (mounted && !_loadedFinalImage) {
precacheImage(imageProvider, context).then((value) {
if (mounted) {
if (mounted && !_loadedFinalImage) {
setState(() {
_imageProvider = imageProvider;
_loadedLargeThumbnail = true;