|
@@ -1,9 +1,11 @@ |
|
|
import 'dart:convert'; |
|
|
import 'dart:convert'; |
|
|
|
|
|
import 'dart:io'; |
|
|
import 'dart:ui'; |
|
|
import 'dart:ui'; |
|
|
|
|
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart'; |
|
|
import 'package:cached_network_image/cached_network_image.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:fluttertoast/fluttertoast.dart'; |
|
|
import 'package:fluttertoast/fluttertoast.dart'; |
|
|
|
|
|
import 'package:path_provider/path_provider.dart'; |
|
|
import 'package:permission_handler/permission_handler.dart'; |
|
|
import 'package:permission_handler/permission_handler.dart'; |
|
|
import 'package:share_extend/share_extend.dart'; |
|
|
import 'package:share_extend/share_extend.dart'; |
|
|
import 'package:sharesdk_plugin/sharesdk_plugin.dart'; |
|
|
import 'package:sharesdk_plugin/sharesdk_plugin.dart'; |
|
@@ -11,9 +13,6 @@ import 'package:zhiying_base_widget/utils/image_download_util/image_download_uti |
|
|
import 'package:zhiying_base_widget/widgets/share/models/share_data_model.dart'; |
|
|
import 'package:zhiying_base_widget/widgets/share/models/share_data_model.dart'; |
|
|
import 'package:zhiying_base_widget/widgets/share/models/share_icon_model.dart'; |
|
|
import 'package:zhiying_base_widget/widgets/share/models/share_icon_model.dart'; |
|
|
import 'package:zhiying_comm/zhiying_comm.dart'; |
|
|
import 'package:zhiying_comm/zhiying_comm.dart'; |
|
|
// import 'package:image_gallery_saver/image_gallery_saver.dart'; |
|
|
|
|
|
|
|
|
|
|
|
import 'package:path_provider/path_provider.dart'; |
|
|
|
|
|
|
|
|
|
|
|
class ShareAlert extends StatelessWidget { |
|
|
class ShareAlert extends StatelessWidget { |
|
|
final String skipIdentifier; |
|
|
final String skipIdentifier; |
|
@@ -67,10 +66,10 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { |
|
|
void initState() { |
|
|
void initState() { |
|
|
NetUtil.request('/api/v1/mod/${widget.skipIdentifier}', |
|
|
NetUtil.request('/api/v1/mod/${widget.skipIdentifier}', |
|
|
method: NetMethod.GET, onCache: (data) { |
|
|
method: NetMethod.GET, onCache: (data) { |
|
|
_parseData(data); |
|
|
|
|
|
}, onSuccess: (data) { |
|
|
|
|
|
_parseData(data); |
|
|
|
|
|
}, onError: (err) {}); |
|
|
|
|
|
|
|
|
_parseData(data); |
|
|
|
|
|
}, onSuccess: (data) { |
|
|
|
|
|
_parseData(data); |
|
|
|
|
|
}, onError: (err) {}); |
|
|
|
|
|
|
|
|
super.initState(); |
|
|
super.initState(); |
|
|
} |
|
|
} |
|
@@ -122,7 +121,7 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { |
|
|
), |
|
|
), |
|
|
Container( |
|
|
Container( |
|
|
margin: |
|
|
margin: |
|
|
EdgeInsets.only(left: 12, right: 12, top: 10, bottom: 10), |
|
|
|
|
|
|
|
|
EdgeInsets.only(left: 12, right: 12, top: 10, bottom: 10), |
|
|
child: _createIcons(), |
|
|
child: _createIcons(), |
|
|
), |
|
|
), |
|
|
GestureDetector( |
|
|
GestureDetector( |
|
@@ -216,6 +215,7 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// mob分享,只能单图分享,多图分享调用系统分享 |
|
|
void _shareByMob(ShareSDKPlatform plateform) async { |
|
|
void _shareByMob(ShareSDKPlatform plateform) async { |
|
|
int count = 0; |
|
|
int count = 0; |
|
|
if (widget.model.poster != null) { |
|
|
if (widget.model.poster != null) { |
|
@@ -238,37 +238,34 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { |
|
|
Fluttertoast.showToast(msg: '暂无权限,分享失败'); |
|
|
Fluttertoast.showToast(msg: '暂无权限,分享失败'); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
// PermissionStatus status = await PermissionHandler().checkPermissionStatus( |
|
|
|
|
|
// PermissionGroup.storage); |
|
|
|
|
|
// if (PermissionStatus.granted != status) { |
|
|
|
|
|
// PermissionHandler().requestPermissions(<PermissionGroup>[ |
|
|
|
|
|
// PermissionGroup.storage, |
|
|
|
|
|
// ]); |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// final result = await ImageGallerySaver.saveImage(widget.model.poster); |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// 保存到本地路径 |
|
|
|
|
|
final tempDir = await getTemporaryDirectory(); |
|
|
|
|
|
final file = await File('${tempDir.path}/image.jpg').create(); |
|
|
|
|
|
file.writeAsBytesSync(widget.model.poster); |
|
|
|
|
|
|
|
|
// var appDocDir = await getTemporaryDirectory(); |
|
|
|
|
|
// final result = await ImageGallerySaver.saveImage( |
|
|
|
|
|
// widget.model.poster, |
|
|
|
|
|
// quality: 60, |
|
|
|
|
|
// name: "hello"); |
|
|
|
|
|
// Logger.debug(result); |
|
|
|
|
|
|
|
|
Logger.debug(file.path); |
|
|
|
|
|
|
|
|
// params = SSDKMap() |
|
|
|
|
|
// ..setGeneral( |
|
|
|
|
|
// widget.model.title, |
|
|
|
|
|
// widget.model.content, |
|
|
|
|
|
// widget.model.poster, |
|
|
|
|
|
// null, |
|
|
|
|
|
// null, |
|
|
|
|
|
// widget.model.url, |
|
|
|
|
|
// null, |
|
|
|
|
|
// null, |
|
|
|
|
|
// null, |
|
|
|
|
|
// null, |
|
|
|
|
|
// SSDKContentTypes.auto, |
|
|
|
|
|
// ); |
|
|
|
|
|
|
|
|
params = SSDKMap() |
|
|
|
|
|
..setGeneral( |
|
|
|
|
|
widget.model.title, |
|
|
|
|
|
widget.model.content, |
|
|
|
|
|
file.path, |
|
|
|
|
|
null, |
|
|
|
|
|
null, |
|
|
|
|
|
widget.model.url, |
|
|
|
|
|
null, |
|
|
|
|
|
null, |
|
|
|
|
|
null, |
|
|
|
|
|
null, |
|
|
|
|
|
SSDKContentTypes.auto, |
|
|
|
|
|
); |
|
|
|
|
|
} catch (err, s) { |
|
|
|
|
|
Logger.error(err.toString(), s.toString()); |
|
|
|
|
|
Fluttertoast.showToast(msg: '分享失败'); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
params = SSDKMap() |
|
|
params = SSDKMap() |
|
|
..setGeneral( |
|
|
..setGeneral( |
|
@@ -304,7 +301,36 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { |
|
|
|
|
|
|
|
|
// 多图分享,调用系统分享 |
|
|
// 多图分享,调用系统分享 |
|
|
void _shareMultipleImages() async { |
|
|
void _shareMultipleImages() async { |
|
|
List<String> paths = await ImageDownloadUtil.download(widget.model.image); |
|
|
|
|
|
|
|
|
List<String> paths = List(); |
|
|
|
|
|
if (widget.model.poster != null) { |
|
|
|
|
|
// 检查并请求权限 |
|
|
|
|
|
var status = await Permission.storage.status; |
|
|
|
|
|
if (status != PermissionStatus.granted) { |
|
|
|
|
|
status = await Permission.storage.request(); |
|
|
|
|
|
} |
|
|
|
|
|
if (status == PermissionStatus.denied) { |
|
|
|
|
|
Fluttertoast.showToast(msg: '暂无权限,分享失败'); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// 保存到本地路径 |
|
|
|
|
|
final tempDir = await getTemporaryDirectory(); |
|
|
|
|
|
final file = await File('${tempDir.path}/image.jpg').create(); |
|
|
|
|
|
file.writeAsBytesSync(widget.model.poster); |
|
|
|
|
|
|
|
|
|
|
|
paths.add(file.path); |
|
|
|
|
|
Logger.debug(file.path); |
|
|
|
|
|
} catch (err, s) { |
|
|
|
|
|
Logger.error(err.toString(), s.toString()); |
|
|
|
|
|
Fluttertoast.showToast(msg: '分享失败'); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<String> downPaths = |
|
|
|
|
|
await ImageDownloadUtil.download(widget.model.image); |
|
|
|
|
|
paths.addAll(downPaths); |
|
|
ShareExtend.shareMultiple(paths, "image", subject: ""); |
|
|
ShareExtend.shareMultiple(paths, "image", subject: ""); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |