opt: 图片预览
This commit is contained in:
@ -1,5 +1,4 @@
|
|||||||
// 内容
|
// 内容
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:pilipala/common/widgets/badge.dart';
|
import 'package:pilipala/common/widgets/badge.dart';
|
||||||
@ -166,31 +165,6 @@ class _ContentState extends State<Content> {
|
|||||||
builder: (BuildContext context) => InteractiveviewerGallery(
|
builder: (BuildContext context) => InteractiveviewerGallery(
|
||||||
sources: picList,
|
sources: picList,
|
||||||
initIndex: initIndex,
|
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) {},
|
onPageChanged: (int pageIndex) {},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import 'package:cached_network_image/cached_network_image.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:pilipala/common/constants.dart';
|
import 'package:pilipala/common/constants.dart';
|
||||||
@ -12,31 +11,6 @@ void onPreviewImg(currentUrl, picList, initIndex, context) {
|
|||||||
builder: (BuildContext context) => InteractiveviewerGallery(
|
builder: (BuildContext context) => InteractiveviewerGallery(
|
||||||
sources: picList,
|
sources: picList,
|
||||||
initIndex: initIndex,
|
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) {},
|
onPageChanged: (int pageIndex) {},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:pilipala/http/read.dart';
|
import 'package:pilipala/http/read.dart';
|
||||||
import 'package:pilipala/models/read/opus.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/hero_dialog_route.dart';
|
||||||
import 'package:pilipala/plugin/pl_gallery/interactiveviewer_gallery.dart';
|
import 'package:pilipala/plugin/pl_gallery/interactiveviewer_gallery.dart';
|
||||||
|
|
||||||
@ -61,31 +60,6 @@ class OpusController extends GetxController {
|
|||||||
builder: (BuildContext context) => InteractiveviewerGallery(
|
builder: (BuildContext context) => InteractiveviewerGallery(
|
||||||
sources: picList,
|
sources: picList,
|
||||||
initIndex: initIndex,
|
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) {},
|
onPageChanged: (int pageIndex) {},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:pilipala/http/read.dart';
|
import 'package:pilipala/http/read.dart';
|
||||||
@ -51,31 +50,6 @@ class ReadPageController extends GetxController {
|
|||||||
builder: (BuildContext context) => InteractiveviewerGallery(
|
builder: (BuildContext context) => InteractiveviewerGallery(
|
||||||
sources: picList,
|
sources: picList,
|
||||||
initIndex: initIndex,
|
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) {},
|
onPageChanged: (int pageIndex) {},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:appscheme/appscheme.dart';
|
import 'package:appscheme/appscheme.dart';
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@ -583,34 +582,6 @@ InlineSpan buildContent(
|
|||||||
builder: (BuildContext context) => InteractiveviewerGallery(
|
builder: (BuildContext context) => InteractiveviewerGallery(
|
||||||
sources: picList,
|
sources: picList,
|
||||||
initIndex: initIndex,
|
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>();
|
|
||||||
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) {},
|
onPageChanged: (int pageIndex) {},
|
||||||
onDismissed: (int value) {
|
onDismissed: (int value) {
|
||||||
print('onDismissed');
|
print('onDismissed');
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// ignore_for_file: constant_identifier_names
|
// ignore_for_file: constant_identifier_names
|
||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
@ -170,31 +169,6 @@ class ChatItem extends StatelessWidget {
|
|||||||
builder: (BuildContext context) => InteractiveviewerGallery(
|
builder: (BuildContext context) => InteractiveviewerGallery(
|
||||||
sources: ctr.picList,
|
sources: ctr.picList,
|
||||||
initIndex: ctr.picList.indexOf(content['url']),
|
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) {},
|
onPageChanged: (int pageIndex) {},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -2,10 +2,12 @@ library interactiveviewer_gallery;
|
|||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:pilipala/utils/download.dart';
|
import 'package:pilipala/utils/download.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
@ -32,7 +34,7 @@ class InteractiveviewerGallery<T> extends StatefulWidget {
|
|||||||
const InteractiveviewerGallery({
|
const InteractiveviewerGallery({
|
||||||
required this.sources,
|
required this.sources,
|
||||||
required this.initIndex,
|
required this.initIndex,
|
||||||
required this.itemBuilder,
|
this.itemBuilder,
|
||||||
this.maxScale = 4.5,
|
this.maxScale = 4.5,
|
||||||
this.minScale = 1.0,
|
this.minScale = 1.0,
|
||||||
this.onPageChanged,
|
this.onPageChanged,
|
||||||
@ -47,7 +49,7 @@ class InteractiveviewerGallery<T> extends StatefulWidget {
|
|||||||
final int initIndex;
|
final int initIndex;
|
||||||
|
|
||||||
/// The item content
|
/// The item content
|
||||||
final IndexedFocusedWidgetBuilder itemBuilder;
|
final IndexedFocusedWidgetBuilder? itemBuilder;
|
||||||
|
|
||||||
final double maxScale;
|
final double maxScale;
|
||||||
|
|
||||||
@ -246,12 +248,15 @@ class _InteractiveviewerGalleryState extends State<InteractiveviewerGallery>
|
|||||||
_doubleTapLocalPosition = details.localPosition;
|
_doubleTapLocalPosition = details.localPosition;
|
||||||
},
|
},
|
||||||
onDoubleTap: onDoubleTap,
|
onDoubleTap: onDoubleTap,
|
||||||
child: widget.itemBuilder(
|
onLongPress: onLongPress,
|
||||||
|
child: widget.itemBuilder != null
|
||||||
|
? widget.itemBuilder!(
|
||||||
context,
|
context,
|
||||||
index,
|
index,
|
||||||
index == currentIndex,
|
index == currentIndex,
|
||||||
_enablePageView,
|
_enablePageView,
|
||||||
),
|
)
|
||||||
|
: _itemBuilder(widget.sources, index),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -302,17 +307,7 @@ class _InteractiveviewerGalleryState extends State<InteractiveviewerGallery>
|
|||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: 1,
|
value: 1,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Clipboard.setData(ClipboardData(
|
onCopyImg(widget.sources[currentIndex!].toString());
|
||||||
text:
|
|
||||||
widget.sources[currentIndex!].toString()))
|
|
||||||
.then((value) {
|
|
||||||
SmartDialog.showToast('已复制到粘贴板');
|
|
||||||
}).catchError((err) {
|
|
||||||
SmartDialog.showNotify(
|
|
||||||
msg: err.toString(),
|
|
||||||
notifyType: NotifyType.error,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
child: const Text("复制图片"),
|
child: const Text("复制图片"),
|
||||||
),
|
),
|
||||||
@ -350,6 +345,41 @@ class _InteractiveviewerGalleryState extends State<InteractiveviewerGallery>
|
|||||||
Share.shareXFiles([XFile(path)], subject: imgUrl);
|
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() {
|
onDoubleTap() {
|
||||||
Matrix4 matrix = _transformationController!.value.clone();
|
Matrix4 matrix = _transformationController!.value.clone();
|
||||||
double currentScale = matrix.row0.x;
|
double currentScale = matrix.row0.x;
|
||||||
@ -396,4 +426,61 @@ class _InteractiveviewerGalleryState extends State<InteractiveviewerGallery>
|
|||||||
.forward(from: 0)
|
.forward(from: 0)
|
||||||
.whenComplete(() => _onScaleChanged(targetScale));
|
.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('保存图片'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user