mod: 图片预览页面样式
This commit is contained in:
@ -2,11 +2,9 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:device_info_plus/device_info_plus.dart';
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'dart:typed_data';
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
|
||||||
class PreviewController extends GetxController {
|
class PreviewController extends GetxController {
|
||||||
@ -17,7 +15,7 @@ class PreviewController extends GetxController {
|
|||||||
bool storage = true;
|
bool storage = true;
|
||||||
bool videos = true;
|
bool videos = true;
|
||||||
bool photos = true;
|
bool photos = true;
|
||||||
bool visiable = true;
|
String currentImgUrl = '';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -26,6 +24,7 @@ class PreviewController extends GetxController {
|
|||||||
initialPage.value = Get.arguments['initialPage']!;
|
initialPage.value = Get.arguments['initialPage']!;
|
||||||
currentPage.value = Get.arguments['initialPage']! + 1;
|
currentPage.value = Get.arguments['initialPage']! + 1;
|
||||||
imgList.value = Get.arguments['imgList'];
|
imgList.value = Get.arguments['imgList'];
|
||||||
|
currentImgUrl = imgList[initialPage.value];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,22 +38,6 @@ class PreviewController extends GetxController {
|
|||||||
// final photosInfo = statuses[Permission.photos].toString();
|
// final photosInfo = statuses[Permission.photos].toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 图片保存
|
|
||||||
void onSaveImg() async {
|
|
||||||
var response = await Dio().get(imgList[initialPage.value],
|
|
||||||
options: Options(responseType: ResponseType.bytes));
|
|
||||||
final result = await ImageGallerySaver.saveImage(
|
|
||||||
Uint8List.fromList(response.data),
|
|
||||||
quality: 100,
|
|
||||||
name: "pic_vvex${DateTime.now().toString().split('-').join()}");
|
|
||||||
if (result != null) {
|
|
||||||
if (result['isSuccess']) {
|
|
||||||
// ignore: avoid_print
|
|
||||||
print('已保存到相册');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 图片分享
|
// 图片分享
|
||||||
void onShareImg() async {
|
void onShareImg() async {
|
||||||
requestPermission();
|
requestPermission();
|
||||||
@ -62,9 +45,15 @@ class PreviewController extends GetxController {
|
|||||||
options: Options(responseType: ResponseType.bytes));
|
options: Options(responseType: ResponseType.bytes));
|
||||||
final temp = await getTemporaryDirectory();
|
final temp = await getTemporaryDirectory();
|
||||||
String imgName =
|
String imgName =
|
||||||
"pic_plpl${DateTime.now().toString().split('-').join()}.jpg";
|
"plpl_pic_${DateTime.now().toString().split('-').join()}.jpg";
|
||||||
var path = '${temp.path}/$imgName';
|
var path = '${temp.path}/$imgName';
|
||||||
File(path).writeAsBytesSync(response.data);
|
File(path).writeAsBytesSync(response.data);
|
||||||
Share.shareXFiles([XFile(path)], subject: imgList[initialPage.value]);
|
Share.shareXFiles([XFile(path)], subject: imgList[initialPage.value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onChange(int index) {
|
||||||
|
initialPage.value = index;
|
||||||
|
currentPage.value = index + 1;
|
||||||
|
currentImgUrl = imgList[index];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,12 @@
|
|||||||
|
|
||||||
import 'package:dismissible_page/dismissible_page.dart';
|
import 'package:dismissible_page/dismissible_page.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:extended_image/extended_image.dart';
|
import 'package:extended_image/extended_image.dart';
|
||||||
|
import 'package:pilipala/plugin/pl_player/index.dart';
|
||||||
|
import 'package:pilipala/utils/download.dart';
|
||||||
import 'controller.dart';
|
import 'controller.dart';
|
||||||
|
|
||||||
typedef DoubleClickAnimationListener = void Function();
|
typedef DoubleClickAnimationListener = void Function();
|
||||||
@ -31,15 +34,69 @@ class _ImagePreviewState extends State<ImagePreview>
|
|||||||
super.initState();
|
super.initState();
|
||||||
// animationController = AnimationController(
|
// animationController = AnimationController(
|
||||||
// vsync: this, duration: const Duration(milliseconds: 400));
|
// vsync: this, duration: const Duration(milliseconds: 400));
|
||||||
|
SystemChrome.setEnabledSystemUIMode(
|
||||||
|
SystemUiMode.immersiveSticky,
|
||||||
|
);
|
||||||
_doubleClickAnimationController = AnimationController(
|
_doubleClickAnimationController = AnimationController(
|
||||||
duration: const Duration(milliseconds: 250), vsync: this);
|
duration: const Duration(milliseconds: 250), vsync: this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onOpenMenu() {
|
||||||
|
SmartDialog.show(
|
||||||
|
useSystem: true,
|
||||||
|
animationType: SmartAnimationType.centerFade_otherSlide,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
clipBehavior: Clip.hardEdge,
|
||||||
|
contentPadding: const EdgeInsets.fromLTRB(0, 12, 0, 12),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
ListTile(
|
||||||
|
onTap: () {
|
||||||
|
_previewController.onShareImg();
|
||||||
|
SmartDialog.dismiss();
|
||||||
|
},
|
||||||
|
dense: true,
|
||||||
|
title: const Text('分享', style: TextStyle(fontSize: 14)),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
onTap: () {
|
||||||
|
Clipboard.setData(
|
||||||
|
ClipboardData(text: _previewController.currentImgUrl))
|
||||||
|
.then((value) {
|
||||||
|
SmartDialog.showToast('已复制到粘贴板');
|
||||||
|
SmartDialog.dismiss();
|
||||||
|
}).catchError((err) {
|
||||||
|
SmartDialog.showNotify(
|
||||||
|
msg: err.toString(),
|
||||||
|
notifyType: NotifyType.error,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
dense: true,
|
||||||
|
title: const Text('复制链接', style: TextStyle(fontSize: 14)),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
onTap: () {
|
||||||
|
DownloadUtils.downloadImg(_previewController.currentImgUrl);
|
||||||
|
},
|
||||||
|
dense: true,
|
||||||
|
title: const Text('保存到手机', style: TextStyle(fontSize: 14)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
// animationController.dispose();
|
// animationController.dispose();
|
||||||
_doubleClickAnimationController.dispose();
|
_doubleClickAnimationController.dispose();
|
||||||
clearGestureDetailsCache();
|
clearGestureDetailsCache();
|
||||||
|
exitFullScreen();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,19 +126,14 @@ class _ImagePreviewState extends State<ImagePreview>
|
|||||||
tag: _previewController
|
tag: _previewController
|
||||||
.imgList[_previewController.initialPage.value],
|
.imgList[_previewController.initialPage.value],
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onLongPress: () => onOpenMenu(),
|
||||||
_previewController.visiable = !_previewController.visiable;
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
child: ExtendedImageGesturePageView.builder(
|
child: ExtendedImageGesturePageView.builder(
|
||||||
controller: ExtendedPageController(
|
controller: ExtendedPageController(
|
||||||
initialPage: _previewController.initialPage.value,
|
initialPage: _previewController.initialPage.value,
|
||||||
pageSpacing: 0,
|
pageSpacing: 0,
|
||||||
),
|
),
|
||||||
onPageChanged: (int index) {
|
onPageChanged: (int index) =>
|
||||||
_previewController.initialPage.value = index;
|
_previewController.onChange(index),
|
||||||
_previewController.currentPage.value = index + 1;
|
|
||||||
},
|
|
||||||
canScrollPage: (GestureDetails? gestureDetails) =>
|
canScrollPage: (GestureDetails? gestureDetails) =>
|
||||||
gestureDetails!.totalScale! <= 1.0,
|
gestureDetails!.totalScale! <= 1.0,
|
||||||
preloadPagesCount: 2,
|
preloadPagesCount: 2,
|
||||||
@ -149,8 +201,10 @@ class _ImagePreviewState extends State<ImagePreview>
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 150.0,
|
width: 150.0,
|
||||||
child:
|
child: LinearProgressIndicator(
|
||||||
LinearProgressIndicator(value: progress),
|
value: progress,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10.0),
|
const SizedBox(height: 10.0),
|
||||||
Text('${((progress ?? 0.0) * 100).toInt()}%'),
|
Text('${((progress ?? 0.0) * 100).toInt()}%'),
|
||||||
@ -179,7 +233,6 @@ class _ImagePreviewState extends State<ImagePreview>
|
|||||||
right: 0,
|
right: 0,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
child: Container(
|
child: Container(
|
||||||
// height: 45,
|
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
bottom: MediaQuery.of(context).padding.bottom, top: 20),
|
bottom: MediaQuery.of(context).padding.bottom, top: 20),
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
@ -193,36 +246,18 @@ class _ImagePreviewState extends State<ImagePreview>
|
|||||||
tileMode: TileMode.mirror,
|
tileMode: TileMode.mirror,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Padding(
|
child: Obx(
|
||||||
padding: const EdgeInsets.only(left: 20, right: 12),
|
() => Text.rich(
|
||||||
child: Row(
|
textAlign: TextAlign.center,
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
TextSpan(
|
||||||
children: [
|
style: const TextStyle(color: Colors.white, fontSize: 15),
|
||||||
Obx(
|
children: [
|
||||||
() => Text.rich(
|
|
||||||
TextSpan(
|
TextSpan(
|
||||||
style: const TextStyle(
|
text: _previewController.currentPage.toString()),
|
||||||
color: Colors.white, fontSize: 18),
|
const TextSpan(text: ' / '),
|
||||||
children: [
|
TextSpan(
|
||||||
TextSpan(
|
text: _previewController.imgList.length.toString()),
|
||||||
text: _previewController.currentPage
|
]),
|
||||||
.toString()),
|
|
||||||
const TextSpan(text: ' / '),
|
|
||||||
TextSpan(
|
|
||||||
text: _previewController.imgList.length
|
|
||||||
.toString()),
|
|
||||||
]),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () => _previewController.onShareImg(),
|
|
||||||
child: const Text('分享')),
|
|
||||||
const SizedBox(width: 10),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () => _previewController.onSaveImg(),
|
|
||||||
child: const Text('保存'))
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -6,7 +6,7 @@ import 'package:image_gallery_saver/image_gallery_saver.dart';
|
|||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
class DownloadUtils {
|
class DownloadUtils {
|
||||||
// 获取存储全县
|
// 获取存储权限
|
||||||
static requestStoragePer() async {
|
static requestStoragePer() async {
|
||||||
Map<Permission, PermissionStatus> statuses = await [
|
Map<Permission, PermissionStatus> statuses = await [
|
||||||
Permission.storage,
|
Permission.storage,
|
||||||
|
Reference in New Issue
Block a user