From a8c89e59b10553727d54966e8b6e8ec8de117ff9 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Thu, 3 Oct 2024 20:35:33 +0800 Subject: [PATCH] =?UTF-8?q?opt:=20=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/dynamics/widgets/content_panel.dart | 26 ---- lib/pages/dynamics/widgets/pic_panel.dart | 26 ---- lib/pages/opus/controller.dart | 26 ---- lib/pages/read/controller.dart | 26 ---- .../detail/reply/widgets/reply_item.dart | 29 ---- .../whisper_detail/widget/chat_item.dart | 26 ---- .../pl_gallery/interactiveviewer_gallery.dart | 125 +++++++++++++++--- 7 files changed, 106 insertions(+), 178 deletions(-) diff --git a/lib/pages/dynamics/widgets/content_panel.dart b/lib/pages/dynamics/widgets/content_panel.dart index 28451dde..c1a6185e 100644 --- a/lib/pages/dynamics/widgets/content_panel.dart +++ b/lib/pages/dynamics/widgets/content_panel.dart @@ -1,5 +1,4 @@ // 内容 -import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:pilipala/common/widgets/badge.dart'; @@ -166,31 +165,6 @@ class _ContentState extends State { builder: (BuildContext context) => InteractiveviewerGallery( sources: picList, initIndex: initIndex, - itemBuilder: ( - BuildContext context, - int index, - bool isFocus, - bool enablePageView, - ) { - return GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - if (enablePageView) { - Navigator.of(context).pop(); - } - }, - child: Center( - child: Hero( - tag: picList[index], - child: CachedNetworkImage( - fadeInDuration: const Duration(milliseconds: 0), - imageUrl: picList[index], - fit: BoxFit.contain, - ), - ), - ), - ); - }, onPageChanged: (int pageIndex) {}, ), ), diff --git a/lib/pages/dynamics/widgets/pic_panel.dart b/lib/pages/dynamics/widgets/pic_panel.dart index 783fe89b..bd3f91f6 100644 --- a/lib/pages/dynamics/widgets/pic_panel.dart +++ b/lib/pages/dynamics/widgets/pic_panel.dart @@ -1,4 +1,3 @@ -import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:pilipala/common/constants.dart'; @@ -12,31 +11,6 @@ void onPreviewImg(currentUrl, picList, initIndex, context) { builder: (BuildContext context) => InteractiveviewerGallery( sources: picList, initIndex: initIndex, - itemBuilder: ( - BuildContext context, - int index, - bool isFocus, - bool enablePageView, - ) { - return GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - if (enablePageView) { - Navigator.of(context).pop(); - } - }, - child: Center( - child: Hero( - tag: picList[index], - child: CachedNetworkImage( - fadeInDuration: const Duration(milliseconds: 0), - imageUrl: picList[index], - fit: BoxFit.contain, - ), - ), - ), - ); - }, onPageChanged: (int pageIndex) {}, ), ), diff --git a/lib/pages/opus/controller.dart b/lib/pages/opus/controller.dart index 3cf844cc..f00c45b5 100644 --- a/lib/pages/opus/controller.dart +++ b/lib/pages/opus/controller.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:pilipala/http/read.dart'; import 'package:pilipala/models/read/opus.dart'; -import 'package:cached_network_image/cached_network_image.dart'; import 'package:pilipala/plugin/pl_gallery/hero_dialog_route.dart'; import 'package:pilipala/plugin/pl_gallery/interactiveviewer_gallery.dart'; @@ -61,31 +60,6 @@ class OpusController extends GetxController { builder: (BuildContext context) => InteractiveviewerGallery( sources: picList, initIndex: initIndex, - itemBuilder: ( - BuildContext context, - int index, - bool isFocus, - bool enablePageView, - ) { - return GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - if (enablePageView) { - Navigator.of(context).pop(); - } - }, - child: Center( - child: Hero( - tag: picList[index], - child: CachedNetworkImage( - fadeInDuration: const Duration(milliseconds: 0), - imageUrl: picList[index], - fit: BoxFit.contain, - ), - ), - ), - ); - }, onPageChanged: (int pageIndex) {}, ), ), diff --git a/lib/pages/read/controller.dart b/lib/pages/read/controller.dart index efa43c98..178ebfda 100644 --- a/lib/pages/read/controller.dart +++ b/lib/pages/read/controller.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:pilipala/http/read.dart'; @@ -51,31 +50,6 @@ class ReadPageController extends GetxController { builder: (BuildContext context) => InteractiveviewerGallery( sources: picList, initIndex: initIndex, - itemBuilder: ( - BuildContext context, - int index, - bool isFocus, - bool enablePageView, - ) { - return GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - if (enablePageView) { - Navigator.of(context).pop(); - } - }, - child: Center( - child: Hero( - tag: picList[index], - child: CachedNetworkImage( - fadeInDuration: const Duration(milliseconds: 0), - imageUrl: picList[index], - fit: BoxFit.contain, - ), - ), - ), - ); - }, onPageChanged: (int pageIndex) {}, ), ), diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 26dc2e5a..8bb6992a 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -1,7 +1,6 @@ import 'dart:math'; import 'package:appscheme/appscheme.dart'; -import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -583,34 +582,6 @@ InlineSpan buildContent( builder: (BuildContext context) => InteractiveviewerGallery( sources: picList, initIndex: initIndex, - itemBuilder: ( - BuildContext context, - int index, - bool isFocus, - bool enablePageView, - ) { - return GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - if (enablePageView) { - Navigator.of(context).pop(); - final MainController mainController = - Get.find(); - mainController.imgPreviewStatus = false; - } - }, - child: Center( - child: Hero( - tag: picList[index] + randomInt, - child: CachedNetworkImage( - fadeInDuration: const Duration(milliseconds: 0), - imageUrl: picList[index], - fit: BoxFit.contain, - ), - ), - ), - ); - }, onPageChanged: (int pageIndex) {}, onDismissed: (int value) { print('onDismissed'); diff --git a/lib/pages/whisper_detail/widget/chat_item.dart b/lib/pages/whisper_detail/widget/chat_item.dart index 7ddd1d83..01ede374 100644 --- a/lib/pages/whisper_detail/widget/chat_item.dart +++ b/lib/pages/whisper_detail/widget/chat_item.dart @@ -2,7 +2,6 @@ // ignore_for_file: constant_identifier_names import 'dart:convert'; -import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; @@ -170,31 +169,6 @@ class ChatItem extends StatelessWidget { builder: (BuildContext context) => InteractiveviewerGallery( sources: ctr.picList, initIndex: ctr.picList.indexOf(content['url']), - itemBuilder: ( - BuildContext context, - int index, - bool isFocus, - bool enablePageView, - ) { - return GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - if (enablePageView) { - Navigator.of(context).pop(); - } - }, - child: Center( - child: Hero( - tag: ctr.picList[index], - child: CachedNetworkImage( - fadeInDuration: const Duration(milliseconds: 0), - imageUrl: ctr.picList[index], - fit: BoxFit.contain, - ), - ), - ), - ); - }, onPageChanged: (int pageIndex) {}, ), ), diff --git a/lib/plugin/pl_gallery/interactiveviewer_gallery.dart b/lib/plugin/pl_gallery/interactiveviewer_gallery.dart index 03ff4642..cd13194e 100644 --- a/lib/plugin/pl_gallery/interactiveviewer_gallery.dart +++ b/lib/plugin/pl_gallery/interactiveviewer_gallery.dart @@ -2,10 +2,12 @@ library interactiveviewer_gallery; import 'dart:io'; +import 'package:cached_network_image/cached_network_image.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; +import 'package:get/get.dart'; import 'package:path_provider/path_provider.dart'; import 'package:pilipala/utils/download.dart'; import 'package:share_plus/share_plus.dart'; @@ -32,7 +34,7 @@ class InteractiveviewerGallery extends StatefulWidget { const InteractiveviewerGallery({ required this.sources, required this.initIndex, - required this.itemBuilder, + this.itemBuilder, this.maxScale = 4.5, this.minScale = 1.0, this.onPageChanged, @@ -47,7 +49,7 @@ class InteractiveviewerGallery extends StatefulWidget { final int initIndex; /// The item content - final IndexedFocusedWidgetBuilder itemBuilder; + final IndexedFocusedWidgetBuilder? itemBuilder; final double maxScale; @@ -246,12 +248,15 @@ class _InteractiveviewerGalleryState extends State _doubleTapLocalPosition = details.localPosition; }, onDoubleTap: onDoubleTap, - child: widget.itemBuilder( - context, - index, - index == currentIndex, - _enablePageView, - ), + onLongPress: onLongPress, + child: widget.itemBuilder != null + ? widget.itemBuilder!( + context, + index, + index == currentIndex, + _enablePageView, + ) + : _itemBuilder(widget.sources, index), ); }, ), @@ -302,17 +307,7 @@ class _InteractiveviewerGalleryState extends State PopupMenuItem( value: 1, onTap: () { - Clipboard.setData(ClipboardData( - text: - widget.sources[currentIndex!].toString())) - .then((value) { - SmartDialog.showToast('已复制到粘贴板'); - }).catchError((err) { - SmartDialog.showNotify( - msg: err.toString(), - notifyType: NotifyType.error, - ); - }); + onCopyImg(widget.sources[currentIndex!].toString()); }, child: const Text("复制图片"), ), @@ -350,6 +345,41 @@ class _InteractiveviewerGalleryState extends State Share.shareXFiles([XFile(path)], subject: imgUrl); } + // 复制图片 + void onCopyImg(String imgUrl) { + Clipboard.setData( + ClipboardData(text: widget.sources[currentIndex!].toString())) + .then((value) { + SmartDialog.showToast('已复制到粘贴板'); + }).catchError((err) { + SmartDialog.showNotify( + msg: err.toString(), + notifyType: NotifyType.error, + ); + }); + } + + Widget _itemBuilder(sources, index) { + return GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + if (_enablePageView) { + Navigator.of(context).pop(); + } + }, + child: Center( + child: Hero( + tag: sources[index], + child: CachedNetworkImage( + fadeInDuration: const Duration(milliseconds: 0), + imageUrl: sources[index], + fit: BoxFit.contain, + ), + ), + ), + ); + } + onDoubleTap() { Matrix4 matrix = _transformationController!.value.clone(); double currentScale = matrix.row0.x; @@ -396,4 +426,61 @@ class _InteractiveviewerGalleryState extends State .forward(from: 0) .whenComplete(() => _onScaleChanged(targetScale)); } + + onLongPress() { + showModalBottomSheet( + context: context, + useRootNavigator: true, + isScrollControlled: true, + builder: (context) { + return Container( + padding: + EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + InkWell( + onTap: () => Get.back(), + child: Container( + height: 35, + padding: const EdgeInsets.only(bottom: 2), + child: Center( + child: Container( + width: 32, + height: 3, + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.outline, + borderRadius: + const BorderRadius.all(Radius.circular(3))), + ), + ), + ), + ), + ListTile( + onTap: () { + onShareImg(widget.sources[currentIndex!]); + Navigator.of(context).pop(); + }, + title: const Text('分享图片'), + ), + ListTile( + onTap: () { + onCopyImg(widget.sources[currentIndex!].toString()); + Navigator.of(context).pop(); + }, + title: const Text('复制图片'), + ), + ListTile( + onTap: () { + DownloadUtils.downloadImg(widget.sources[currentIndex!]); + Navigator.of(context).pop(); + }, + title: const Text('保存图片'), + ), + ], + ), + ); + }, + ); + } }