From 06d8296939a5acb7eec441aa342e0391e8eb97bb Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Wed, 8 Oct 2025 15:52:32 +0800 Subject: [PATCH] tweaks Signed-off-by: bggRGjQaUbCoE --- .../{ => image}/cached_network_svg_image.dart | 15 +-- .../interactiveviewer_gallery.dart | 108 +++--------------- lib/pages/article/widgets/opus_content.dart | 2 +- pubspec.lock | 4 +- 4 files changed, 28 insertions(+), 101 deletions(-) rename lib/common/widgets/{ => image}/cached_network_svg_image.dart (96%) diff --git a/lib/common/widgets/cached_network_svg_image.dart b/lib/common/widgets/image/cached_network_svg_image.dart similarity index 96% rename from lib/common/widgets/cached_network_svg_image.dart rename to lib/common/widgets/image/cached_network_svg_image.dart index efc38df2..a4819211 100644 --- a/lib/common/widgets/cached_network_svg_image.dart +++ b/lib/common/widgets/image/cached_network_svg_image.dart @@ -124,9 +124,7 @@ class _CachedNetworkSVGImageState extends State { Future _loadImage() async { try { - var file = (await widget._cacheManager.getFileFromMemory( - _cacheKey, - ))?.file; + var file = (await widget._cacheManager.getFileFromCache(_cacheKey))?.file; file ??= await widget._cacheManager.getSingleFile( widget._url, @@ -173,15 +171,14 @@ class _CachedNetworkSVGImageState extends State { if (mounted) { setState(() {}); } else { - SchedulerBinding.instance.addPostFrameCallback((_) => setState(() {})); + SchedulerBinding.instance.addPostFrameCallback((_) { + if (mounted) { + setState(() {}); + } + }); } } - @override - void dispose() { - super.dispose(); - } - @override Widget build(BuildContext context) { return SizedBox( diff --git a/lib/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart b/lib/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart index 56700300..53d60f5d 100644 --- a/lib/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart +++ b/lib/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart @@ -78,8 +78,8 @@ class InteractiveviewerGallery extends StatefulWidget { class _InteractiveviewerGalleryState extends State with SingleTickerProviderStateMixin { - PageController? _pageController; - TransformationController? _transformationController; + late final PageController _pageController; + late final TransformationController _transformationController; /// The controller to animate the transformation value of the /// [InteractiveViewer] when it should reset. @@ -109,24 +109,25 @@ class _InteractiveviewerGalleryState extends State duration: const Duration(milliseconds: 300), )..addListener(listener); - var item = widget.sources[currentIndex.value]; + final item = widget.sources[currentIndex.value]; if (item.sourceType == SourceType.livePhoto) { _onPlay(item.liveUrl!); } } void listener() { - _transformationController!.value = _animation?.value ?? Matrix4.identity(); + _transformationController.value = _animation?.value ?? Matrix4.identity(); } @override void dispose() { widget.onClose?.call(true); _player?.dispose(); - _pageController?.dispose(); + _pageController.dispose(); _animationController ..removeListener(listener) ..dispose(); + _transformationController.dispose(); for (var item in widget.sources) { if (item.sourceType == SourceType.networkImage) { CachedNetworkImageProvider(_getActualUrl(item.url)).evict(); @@ -160,7 +161,7 @@ class _InteractiveviewerGalleryState extends State /// When the left boundary has been hit after scaling up the source, the page /// view swiping gets enabled if it has a page to swipe to. void _onLeftBoundaryHit() { - if (!_enablePageView && _pageController!.page!.floor() > 0) { + if (!_enablePageView && _pageController.page!.floor() > 0) { setState(() { _enablePageView = true; }); @@ -171,7 +172,7 @@ class _InteractiveviewerGalleryState extends State /// view swiping gets enabled if it has a page to swipe to. void _onRightBoundaryHit() { if (!_enablePageView && - _pageController!.page!.floor() < widget.sources.length - 1) { + _pageController.page!.floor() < widget.sources.length - 1) { setState(() { _enablePageView = true; }); @@ -206,12 +207,12 @@ class _InteractiveviewerGalleryState extends State _onPlay(item.liveUrl!); } widget.onPageChanged?.call(page); - if (_transformationController!.value != Matrix4.identity()) { + if (_transformationController.value != Matrix4.identity()) { // animate the reset for the transformation of the interactive viewer _animation = Matrix4Tween( - begin: _transformationController!.value, + begin: _transformationController.value, end: Matrix4.identity(), ).animate( CurveTween(curve: Curves.easeOut).animate(_animationController), @@ -232,7 +233,7 @@ class _InteractiveviewerGalleryState extends State widget.onClose!(false); } else { Get.back(); - widget.onDismissed?.call(_pageController!.page!.floor()); + widget.onDismissed?.call(_pageController.page!.floor()); } } @@ -322,83 +323,12 @@ class _InteractiveviewerGalleryState extends State ), ) : null, - child: Stack( - clipBehavior: Clip.none, - alignment: Alignment.center, - children: [ - Align( - alignment: Alignment.centerLeft, - child: IconButton( - icon: const Icon(Icons.close, color: Colors.white), - onPressed: onClose, - ), - ), - if (widget.sources.length > 1) - Align( - alignment: Alignment.center, - child: Obx( - () => Text( - "${currentIndex.value + 1}/${widget.sources.length}", - style: const TextStyle(color: Colors.white), - ), - ), - ), - if (widget.sources[currentIndex.value].sourceType != - SourceType.fileImage) - Align( - alignment: Alignment.centerRight, - child: PopupMenuButton( - itemBuilder: (context) { - final item = widget.sources[currentIndex.value]; - return [ - if (Utils.isMobile) - PopupMenuItem( - onTap: () => ImageUtils.onShareImg(item.url), - child: const Text("分享图片"), - ), - PopupMenuItem( - onTap: () => Utils.copyText(item.url), - child: const Text("复制链接"), - ), - PopupMenuItem( - onTap: () => ImageUtils.downloadImg( - this.context, - [item.url], - ), - child: const Text("保存图片"), - ), - if (Utils.isDesktop) - PopupMenuItem( - onTap: () => PageUtils.launchURL(item.url), - child: const Text("网页打开"), - ) - else if (widget.sources.length > 1) - PopupMenuItem( - onTap: () => ImageUtils.downloadImg( - this.context, - widget.sources.map((item) => item.url).toList(), - ), - child: const Text("保存全部"), - ), - if (item.sourceType == SourceType.livePhoto) - PopupMenuItem( - onTap: () { - ImageUtils.downloadLivePhoto( - context: this.context, - url: item.url, - liveUrl: item.liveUrl!, - width: item.width!, - height: item.height!, - ); - }, - child: const Text("保存 Live Photo"), - ), - ]; - }, - child: const Icon(Icons.more_horiz, color: Colors.white), - ), - ), - ], + alignment: Alignment.center, + child: Obx( + () => Text( + "${currentIndex.value + 1}/${widget.sources.length}", + style: const TextStyle(color: Colors.white), + ), ), ), ), @@ -444,7 +374,7 @@ class _InteractiveviewerGalleryState extends State } void onDoubleTap() { - Matrix4 matrix = _transformationController!.value.clone(); + Matrix4 matrix = _transformationController.value.clone(); double currentScale = matrix.row0.x; double targetScale = widget.minScale; @@ -481,7 +411,7 @@ class _InteractiveviewerGalleryState extends State _animation = Matrix4Tween( - begin: _transformationController!.value, + begin: _transformationController.value, end: matrix, ).animate( CurveTween(curve: Curves.easeOut).animate(_animationController), diff --git a/lib/pages/article/widgets/opus_content.dart b/lib/pages/article/widgets/opus_content.dart index 6e25d8b5..7400797e 100644 --- a/lib/pages/article/widgets/opus_content.dart +++ b/lib/pages/article/widgets/opus_content.dart @@ -1,6 +1,6 @@ import 'dart:math'; -import 'package:PiliPlus/common/widgets/cached_network_svg_image.dart'; +import 'package:PiliPlus/common/widgets/image/cached_network_svg_image.dart'; import 'package:PiliPlus/common/widgets/image/custom_grid_view.dart'; import 'package:PiliPlus/common/widgets/image/network_img_layer.dart'; import 'package:PiliPlus/http/constants.dart'; diff --git a/pubspec.lock b/pubspec.lock index e26d269a..1e58c544 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1965,10 +1965,10 @@ packages: dependency: transitive description: name: win32 - sha256: "66814138c3562338d05613a6e368ed8cfb237ad6d64a9e9334be3f309acfca03" + sha256: d7cb55e04cd34096cd3a79b3330245f54cb96a370a1c27adb3c84b917de8b08e url: "https://pub.dev" source: hosted - version: "5.14.0" + version: "5.15.0" win32_registry: dependency: transitive description: