diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index d967988..1813927 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -614,7 +614,7 @@ "languageVersion": "2.1" } ], - "generated": "2020-10-13T02:42:36.621853Z", + "generated": "2020-10-13T08:45:20.936142Z", "generator": "pub", "generatorVersion": "2.8.2" } diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 131eab7..42522d5 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -92,50 +92,50 @@ android { // // // 签名配置 - signingConfigs { - // 智夜生活 - zhiying { - storeFile file('zhiying.jks') - storePassword 'zhioscom' - keyAlias 'zysh' - keyPassword 'zhioscom' - v1SigningEnabled true - v2SigningEnabled true - } - - } - - flavorDimensions "app" - - - // 应用信息配置 - productFlavors { - // 智夜生活 - zhiying { - applicationId "cn.zhios.zhiying" - versionCode 1 - dimension "app" - versionName '1.0.0' - // 签名信息 - signingConfig signingConfigs.zhiying - } - } - - // 打包脚本 - android.applicationVariants.all { variant -> - if (variant.buildType.name != "debug") { - variant.getPackageApplicationProvider().get().outputDirectory = new File(project.rootDir.absolutePath + "/app/build/outputs/apk") - } +// signingConfigs { +// // 智夜生活 +// zhiying { +// storeFile file('zhiying.jks') +// storePassword 'zhioscom' +// keyAlias 'zysh' +// keyPassword 'zhioscom' +// v1SigningEnabled true +// v2SigningEnabled true +// } +// +// } +// +// flavorDimensions "app" +// +// +// // 应用信息配置 +// productFlavors { +// // 智夜生活 +// zhiying { +// applicationId "cn.zhios.zhiying" +// versionCode 1 +// dimension "app" +// versionName '1.0.0' +// // 签名信息 +// signingConfig signingConfigs.zhiying +// } +// } - variant.outputs.all { output -> - def outputFile = output.outputFile - if (outputFile != null && outputFile.name.endsWith('.apk')) { - //这里修改apk文件名 - def fileName = "${variant.productFlavors[0].name}_${releaseTime()}01_&V${variant.productFlavors[0].versionCode}.apk" - outputFileName = fileName - } - } - } +// // 打包脚本 +// android.applicationVariants.all { variant -> +// if (variant.buildType.name != "debug") { +// variant.getPackageApplicationProvider().get().outputDirectory = new File(project.rootDir.absolutePath + "/app/build/outputs/apk") +// } +// +// variant.outputs.all { output -> +// def outputFile = output.outputFile +// if (outputFile != null && outputFile.name.endsWith('.apk')) { +// //这里修改apk文件名 +// def fileName = "${variant.productFlavors[0].name}_${releaseTime()}01_&V${variant.productFlavors[0].versionCode}.apk" +// outputFileName = fileName +// } +// } +// } configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> diff --git a/lib/pages/goods_share_page/goods_share_image/goods_share_image.dart b/lib/pages/goods_share_page/goods_share_image/goods_share_image.dart index a2c3321..26ae271 100644 --- a/lib/pages/goods_share_page/goods_share_image/goods_share_image.dart +++ b/lib/pages/goods_share_page/goods_share_image/goods_share_image.dart @@ -24,6 +24,8 @@ import 'package:zhiying_base_widget/widgets/public/custom_button/custom_button_m import 'package:zhiying_base_widget/widgets/share/models/share_data_model.dart'; import 'package:zhiying_base_widget/widgets/share/share_alert.dart'; +import 'package:permission_handler/permission_handler.dart'; + class GoodsShareImage extends StatefulWidget { final Map model; final GoodsShareTempDataModel datas; @@ -195,51 +197,51 @@ class _GoodsShareImageState extends State btnCopy == null ? Container() : GestureDetector( - child: Container( - width: 95, - height: 36, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(18), - ), - child: CustomButton(btnCopy)), - onTap: () { - Clipboard.setData(ClipboardData(text: _content)); - Fluttertoast.showToast(msg: '文案已复制'); - }, + child: Container( + width: 95, + height: 36, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(18), ), + child: CustomButton(btnCopy)), + onTap: () { + Clipboard.setData(ClipboardData(text: _content)); + Fluttertoast.showToast(msg: '文案已复制'); + }, + ), btnSave == null ? Container() : GestureDetector( - child: Container( - margin: EdgeInsets.only(left: 5), - width: 95, - height: 36, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(18), - ), - child: CustomButton(btnSave), - ), - onTap: () { - _saveImages(); - }, - ), + child: Container( + margin: EdgeInsets.only(left: 5), + width: 95, + height: 36, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(18), + ), + child: CustomButton(btnSave), + ), + onTap: () { + _saveImages(); + }, + ), btnShare == null ? Container() : Expanded( - child: GestureDetector( - child: Container( - margin: EdgeInsets.only(left: 5), - // width: 95, - height: 36, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(18), - ), - child: CustomButton(btnShare)), - onTap: () { - _showShareAlert(); - }, + child: GestureDetector( + child: Container( + margin: EdgeInsets.only(left: 5), + // width: 95, + height: 36, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(18), ), - ), + child: CustomButton(btnShare)), + onTap: () { + _showShareAlert(); + }, + ), + ), ], ), ), @@ -266,6 +268,17 @@ class _GoodsShareImageState extends State Fluttertoast.showToast(msg: '请选择要保存的图片'); return; } + + //检查是否有存储权限 + var status = await Permission.photos.status; + if (status != PermissionStatus.granted) { + status = await Permission.photos.request(); + } + if (status == PermissionStatus.denied) { + Fluttertoast.showToast(msg: '暂无权限,保存失败'); + return null; + } + bool isSaveSuccess = false; if (_shareModel.poster != null) { isSaveSuccess = await SaveImage.save(imageBytes: _shareModel.poster); @@ -290,7 +303,7 @@ class _GoodsShareImageState extends State ui.Image image = await boundary.toImage(pixelRatio: 2.0); // 注意:png是压缩后格式,如果需要图片的原始像素数据,请使用rawRgba ByteData byteData = - await image.toByteData(format: ui.ImageByteFormat.png); + await image.toByteData(format: ui.ImageByteFormat.png); Uint8List pngBytes = byteData.buffer.asUint8List(); _shareModel.poster = pngBytes; } @@ -327,11 +340,12 @@ class _GoodsShareImageState extends State showCupertinoModalPopup( context: context, - builder: (context) => ShareAlert( - _shareModel, - 'pub.flutter.share_icon', - // child: GoodsShareAlertContent(), - ), + builder: (context) => + ShareAlert( + _shareModel, + 'pub.flutter.share_icon', + // child: GoodsShareAlertContent(), + ), ); } } diff --git a/lib/pages/goods_share_page/models/goods_share_poster_model.dart b/lib/pages/goods_share_page/models/goods_share_poster_model.dart index 3e0a826..a610cfe 100644 --- a/lib/pages/goods_share_page/models/goods_share_poster_model.dart +++ b/lib/pages/goods_share_page/models/goods_share_poster_model.dart @@ -3,6 +3,7 @@ class GoodsSharePosterModel { String avatar; String title; String provider; + String providerName; String posterImage; String inviteCode; String couponPrice; @@ -15,6 +16,7 @@ class GoodsSharePosterModel { this.avatar, this.title, this.provider, + this.providerName, this.posterImage, this.inviteCode, this.couponPrice, @@ -27,6 +29,7 @@ class GoodsSharePosterModel { avatar = json['avatar']; title = json['title']; provider = json['provider']; + providerName = json['provider_name']; posterImage = json['poster_image']; inviteCode = json['invite_code']; couponPrice = json['coupon_price']; @@ -41,6 +44,7 @@ class GoodsSharePosterModel { data['avatar'] = this.avatar; data['title'] = this.title; data['provider'] = this.provider; + data['provider_name'] = this.providerName; data['poster_image'] = this.posterImage; data['invite_code'] = this.inviteCode; data['coupon_price'] = this.couponPrice; diff --git a/lib/template/goods_share_template/goods_share_template.dart b/lib/template/goods_share_template/goods_share_template.dart index 17377b0..fbde4e3 100644 --- a/lib/template/goods_share_template/goods_share_template.dart +++ b/lib/template/goods_share_template/goods_share_template.dart @@ -156,7 +156,7 @@ class GoodsShareTemplate extends StatelessWidget { padding: EdgeInsets.only(left: 2, right: 2, top: 3, bottom: 3), margin: EdgeInsets.only(right: 4), child: Text( - model?.provider ?? '', + model?.providerName ?? '', style: TextStyle( fontSize: 9, height: 1, diff --git a/lib/widgets/share/share_alert.dart b/lib/widgets/share/share_alert.dart index 1ed768c..0fcbf36 100644 --- a/lib/widgets/share/share_alert.dart +++ b/lib/widgets/share/share_alert.dart @@ -66,10 +66,10 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { void initState() { NetUtil.request('/api/v1/mod/${widget.skipIdentifier}', method: NetMethod.GET, onCache: (data) { - _parseData(data); - }, onSuccess: (data) { - _parseData(data); - }, onError: (err) {}); + _parseData(data); + }, onSuccess: (data) { + _parseData(data); + }, onError: (err) {}); super.initState(); } @@ -121,7 +121,7 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { ), Container( margin: - EdgeInsets.only(left: 12, right: 12, top: 10, bottom: 10), + EdgeInsets.only(left: 12, right: 12, top: 10, bottom: 10), child: _createIcons(), ), GestureDetector( @@ -229,50 +229,30 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { } SSDKMap params; 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); - - Logger.debug(file.path); - + String path = await _savePoster(); + if (path != null && path != '') { params = SSDKMap() ..setGeneral( - widget.model.title, - widget.model.content, - file.path, + widget.model?.title ?? '', + widget.model?.content ?? '', + Platform.isIOS ? path : null, null, + Platform.isAndroid ? path : null, null, - widget.model.url, null, null, null, null, - SSDKContentTypes.auto, + SSDKContentTypes.image, ); - } catch (err, s) { - Logger.error(err.toString(), s.toString()); - Fluttertoast.showToast(msg: '分享失败'); - return; } } else { params = SSDKMap() ..setGeneral( - widget.model.title, - widget.model.content, - widget.model.image, - null, + widget.model?.title ?? '', + widget.model?.content ?? '', + Platform.isIOS ? widget.model.image : null, + Platform.isAndroid ? widget.model.image.first : null, null, widget.model.url, null, @@ -291,17 +271,29 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { // 系统分享,只能分享图片或者文字,不能组合分享 void _shareBySystem() async { - if (widget.model.image.length >= 1) { + int count = 0; + if (widget.model.poster != null) { + count++; + } + count += (widget.model?.image?.length ?? 0); + // 多图分享 + if (count > 1) { _shareMultipleImages(); return; + } + + if (widget.model.poster != null) { + String path = await _savePoster(); + if (path != null && path != '') { + ShareExtend.share(path, 'image'); + } } else { ShareExtend.share(widget.model.content, 'text'); } } - // 多图分享,调用系统分享 - void _shareMultipleImages() async { - List paths = List(); + Future _savePoster() async { + String path; if (widget.model.poster != null) { // 检查并请求权限 var status = await Permission.storage.status; @@ -310,7 +302,7 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { } if (status == PermissionStatus.denied) { Fluttertoast.showToast(msg: '暂无权限,分享失败'); - return; + return null; } try { @@ -319,17 +311,27 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { final file = await File('${tempDir.path}/image.jpg').create(); file.writeAsBytesSync(widget.model.poster); - paths.add(file.path); + path = file.path; Logger.debug(file.path); } catch (err, s) { Logger.error(err.toString(), s.toString()); Fluttertoast.showToast(msg: '分享失败'); - return; + return null; } } + return path; + } + + // 多图分享,调用系统分享 + void _shareMultipleImages() async { + List paths = List(); + String path = await _savePoster(); + if (path != null && path != '') { + paths.add(path); + } List downPaths = - await ImageDownloadUtil.download(widget.model.image); + await ImageDownloadUtil.download(widget.model.image); paths.addAll(downPaths); ShareExtend.shareMultiple(paths, "image", subject: ""); }