From 83b0ff02e4ddbd62d06dad8f54721ad3cecbf833 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sun, 3 Mar 2024 18:32:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=BE=E7=89=87=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E6=94=BE=E5=A4=A7=E3=80=81=E5=8F=96=E6=B6=88=E4=B8=8B=E6=BB=91?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E5=9B=BE=E7=89=87=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/preview/view.dart | 256 ++++++++++++++++++------------------ 1 file changed, 130 insertions(+), 126 deletions(-) diff --git a/lib/pages/preview/view.dart b/lib/pages/preview/view.dart index dcffc9730..13868d370 100644 --- a/lib/pages/preview/view.dart +++ b/lib/pages/preview/view.dart @@ -135,115 +135,103 @@ class _ImagePreviewState extends State ), body: Stack( children: [ - DismissiblePage( - backgroundColor: Colors.transparent, - onDismissed: () { - Navigator.of(context).pop(); - }, - // Note that scrollable widget inside DismissiblePage might limit the functionality - // If scroll direction matches DismissiblePage direction - direction: DismissiblePageDismissDirection.down, - disabled: _dismissDisabled, - isFullScreen: true, - child: GestureDetector( - onLongPress: () => onOpenMenu(), - child: ExtendedImageGesturePageView.builder( - controller: ExtendedPageController( - initialPage: _previewController.initialPage.value, - pageSpacing: 0, - ), - onPageChanged: (int index) => - _previewController.onChange(index), - canScrollPage: (GestureDetails? gestureDetails) => - gestureDetails!.totalScale! <= 1.0, - itemCount: widget.imgList!.length, - itemBuilder: (BuildContext context, int index) { - return ExtendedImage.network( - widget.imgList![index], - fit: BoxFit.contain, - mode: ExtendedImageMode.gesture, - onDoubleTap: (ExtendedImageGestureState state) { - final Offset? pointerDownPosition = - state.pointerDownPosition; - final double? begin = state.gestureDetails!.totalScale; - double end; + GestureDetector( + onLongPress: () => onOpenMenu(), + child: ExtendedImageGesturePageView.builder( + controller: ExtendedPageController( + initialPage: _previewController.initialPage.value, + pageSpacing: 0, + ), + onPageChanged: (int index) => _previewController.onChange(index), + canScrollPage: (GestureDetails? gestureDetails) => + gestureDetails!.totalScale! <= 1.0, + itemCount: widget.imgList!.length, + itemBuilder: (BuildContext context, int index) { + return ExtendedImage.network( + widget.imgList![index], + fit: BoxFit.contain, + mode: ExtendedImageMode.gesture, + onDoubleTap: (ExtendedImageGestureState state) { + final Offset? pointerDownPosition = + state.pointerDownPosition; + final double? begin = state.gestureDetails!.totalScale; + double end; - //remove old - _doubleClickAnimation - ?.removeListener(_doubleClickAnimationListener); + //remove old + _doubleClickAnimation + ?.removeListener(_doubleClickAnimationListener); - //stop pre - _doubleClickAnimationController.stop(); + //stop pre + _doubleClickAnimationController.stop(); - //reset to use - _doubleClickAnimationController.reset(); + //reset to use + _doubleClickAnimationController.reset(); - if (begin == doubleTapScales[0]) { - setState(() { - _dismissDisabled = true; - }); - end = doubleTapScales[1]; - } else { - setState(() { - _dismissDisabled = false; - }); - end = doubleTapScales[0]; - } + if (begin == doubleTapScales[0]) { + setState(() { + _dismissDisabled = true; + }); + end = doubleTapScales[1]; + } else { + setState(() { + _dismissDisabled = false; + }); + end = doubleTapScales[0]; + } - _doubleClickAnimationListener = () { - state.handleDoubleTap( - scale: _doubleClickAnimation!.value, - doubleTapPosition: pointerDownPosition); - }; - _doubleClickAnimation = _doubleClickAnimationController - .drive(Tween(begin: begin, end: end)); + _doubleClickAnimationListener = () { + state.handleDoubleTap( + scale: _doubleClickAnimation!.value, + doubleTapPosition: pointerDownPosition); + }; + _doubleClickAnimation = _doubleClickAnimationController + .drive(Tween(begin: begin, end: end)); - _doubleClickAnimation! - .addListener(_doubleClickAnimationListener); + _doubleClickAnimation! + .addListener(_doubleClickAnimationListener); - _doubleClickAnimationController.forward(); - }, - // ignore: body_might_complete_normally_nullable - loadStateChanged: (ExtendedImageState state) { - if (state.extendedImageLoadState == LoadState.loading) { - final ImageChunkEvent? loadingProgress = - state.loadingProgress; - final double? progress = - loadingProgress?.expectedTotalBytes != null - ? loadingProgress!.cumulativeBytesLoaded / - loadingProgress.expectedTotalBytes! - : null; - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - SizedBox( - width: 150.0, - child: LinearProgressIndicator( - value: progress, - color: Colors.white, - ), + _doubleClickAnimationController.forward(); + }, + // ignore: body_might_complete_normally_nullable + loadStateChanged: (ExtendedImageState state) { + if (state.extendedImageLoadState == LoadState.loading) { + final ImageChunkEvent? loadingProgress = + state.loadingProgress; + final double? progress = + loadingProgress?.expectedTotalBytes != null + ? loadingProgress!.cumulativeBytesLoaded / + loadingProgress.expectedTotalBytes! + : null; + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SizedBox( + width: 150.0, + child: LinearProgressIndicator( + value: progress, + color: Colors.white, ), - // const SizedBox(height: 10.0), - // Text('${((progress ?? 0.0) * 100).toInt()}%',), - ], - ), - ); - } - }, - initGestureConfigHandler: (ExtendedImageState state) { - return GestureConfig( - inPageView: true, - initialScale: 1.0, - maxScale: 5.0, - animationMaxScale: 6.0, - initialAlignment: InitialAlignment.center, + ), + // const SizedBox(height: 10.0), + // Text('${((progress ?? 0.0) * 100).toInt()}%',), + ], + ), ); - }, - ); - }, - ), + } + }, + initGestureConfigHandler: (ExtendedImageState state) { + return GestureConfig( + inPageView: true, + initialScale: 1.0, + maxScale: 5.0, + animationMaxScale: 6.0, + initialAlignment: InitialAlignment.center, + ); + }, + ); + }, ), ), Positioned( @@ -251,33 +239,49 @@ class _ImagePreviewState extends State right: 0, bottom: 0, child: Container( - padding: EdgeInsets.only( - bottom: MediaQuery.of(context).padding.bottom + 30), - decoration: const BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - colors: [ - Colors.transparent, - Colors.black87, - ], - tileMode: TileMode.mirror, + padding: EdgeInsets.only( + left: 20, + right: 20, + bottom: MediaQuery.of(context).padding.bottom + 30), + decoration: const BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [ + Colors.transparent, + Colors.black87, + ], + tileMode: TileMode.mirror, + ), ), - ), - child: Obx( - () => Text.rich( - textAlign: TextAlign.center, - TextSpan( - style: const TextStyle(color: Colors.white, fontSize: 15), - children: [ - TextSpan( - text: _previewController.currentPage.toString()), - const TextSpan(text: ' / '), - TextSpan(text: widget.imgList!.length.toString()), - ]), - ), - ), - ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + widget.imgList!.length > 1 + ? Obx( + () => Text.rich( + textAlign: TextAlign.center, + TextSpan( + style: const TextStyle( + color: Colors.white, fontSize: 16), + children: [ + TextSpan( + text: _previewController.currentPage + .toString()), + const TextSpan(text: ' / '), + TextSpan( + text: + widget.imgList!.length.toString()), + ]), + ), + ) + : const SizedBox(), + IconButton( + onPressed: () => Get.back(), + icon: const Icon(Icons.close, color: Colors.white), + ), + ], + )), ), ], ),