基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

215 lines
6.1 KiB

  1. import 'dart:io';
  2. import 'dart:ui';
  3. import 'package:flutter/material.dart';
  4. import 'package:sharesdk_plugin/sharesdk_plugin.dart';
  5. import 'package:zhiying_base_widget/utils/image_download_util/image_download_util.dart';
  6. import 'package:zhiying_base_widget/widgets/share/models/share_data_model.dart';
  7. import 'package:zhiying_base_widget/widgets/share/models/share_plateform.dart';
  8. import 'package:zhiying_comm/zhiying_comm.dart';
  9. import 'package:share_extend/share_extend.dart';
  10. class ShareAlert extends StatelessWidget {
  11. final Widget child;
  12. final ShareDataModel model;
  13. const ShareAlert(this.model, {Key key, this.child}) : super(key: key); // 中间视图
  14. @override
  15. Widget build(BuildContext context) {
  16. return GestureDetector(
  17. child: Scaffold(
  18. backgroundColor: Colors.transparent,
  19. body: BackdropFilter(
  20. filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5), //背景
  21. child: Container(
  22. child: Column(
  23. children: <Widget>[
  24. Expanded(
  25. child: Center(child: child ?? Container()),
  26. ),
  27. _ShareAlertContent(this.model),
  28. ],
  29. ),
  30. ), // 模糊化
  31. ),
  32. ),
  33. onTap: () {
  34. Navigator.of(context).pop();
  35. },
  36. );
  37. }
  38. }
  39. class _ShareAlertContent extends StatelessWidget {
  40. final ShareDataModel model;
  41. const _ShareAlertContent(this.model, {Key key}) : super(key: key);
  42. @override
  43. Widget build(BuildContext context) {
  44. return GestureDetector(
  45. onTap: () {},
  46. child: Container(
  47. width: double.infinity,
  48. decoration: BoxDecoration(
  49. color: Colors.white,
  50. borderRadius: BorderRadius.only(
  51. topLeft: Radius.circular(12),
  52. topRight: Radius.circular(12),
  53. ),
  54. ),
  55. child: SafeArea(
  56. top: false,
  57. child: Column(
  58. children: <Widget>[
  59. Container(
  60. margin: EdgeInsets.only(top: 8, bottom: 8),
  61. width: 62,
  62. height: 4,
  63. decoration: BoxDecoration(
  64. color: Color(0xffd8d8d8),
  65. borderRadius: BorderRadius.circular(2)),
  66. ),
  67. Text(
  68. '分享至',
  69. style: TextStyle(
  70. fontSize: 15,
  71. color: Color(0xff333333),
  72. fontWeight: FontWeight.bold),
  73. ),
  74. Container(
  75. margin:
  76. EdgeInsets.only(left: 12, right: 12, top: 10, bottom: 10),
  77. child: _createIcons(),
  78. ),
  79. GestureDetector(
  80. child: Container(
  81. margin: EdgeInsets.only(left: 12, right: 12, bottom: 10),
  82. padding: EdgeInsets.all(12),
  83. decoration: BoxDecoration(
  84. color: Color(0xfff3f3f3),
  85. borderRadius: BorderRadius.circular(8)),
  86. child: Center(
  87. child: Text(
  88. '取消',
  89. style: TextStyle(
  90. fontSize: 12,
  91. fontWeight: FontWeight.bold,
  92. color: Color(0xff999999)),
  93. ),
  94. ),
  95. ),
  96. onTap: () {
  97. Navigator.of(context).pop();
  98. },
  99. )
  100. ],
  101. ),
  102. ),
  103. ),
  104. );
  105. }
  106. Widget _createIcons() {
  107. return Wrap(
  108. spacing: 10,
  109. runSpacing: 10,
  110. children: List.generate(6, (index) {
  111. return _createIcon();
  112. }),
  113. );
  114. }
  115. Widget _createIcon() {
  116. return GestureDetector(
  117. child: Container(
  118. width: 60,
  119. child: Column(
  120. children: <Widget>[
  121. Container(
  122. width: 40,
  123. height: 40,
  124. decoration: BoxDecoration(
  125. borderRadius: BorderRadius.circular(20),
  126. color: Colors.redAccent),
  127. ),
  128. Padding(
  129. padding: const EdgeInsets.only(top: 2, bottom: 2),
  130. child: Text(
  131. '分享平台',
  132. style: TextStyle(
  133. fontSize: 12,
  134. color: Color(0xff333333),
  135. fontWeight: FontWeight.bold),
  136. ),
  137. ),
  138. ],
  139. ),
  140. ),
  141. onTap: () {
  142. _shareByMob(SharePlateform.qq);
  143. },
  144. );
  145. }
  146. void _shareByMob(SharePlateform plateform) async {
  147. //单独公共分享
  148. SSDKMap params = SSDKMap()
  149. ..setGeneral(
  150. model.title,
  151. model.content,
  152. model.image,
  153. null,
  154. null,
  155. model.url,
  156. null,
  157. null,
  158. null,
  159. null,
  160. SSDKContentTypes.auto,
  161. );
  162. ShareSDKPlatform p = ShareSDKPlatforms.wechatSession;
  163. switch (plateform) {
  164. case SharePlateform.wechatSession:
  165. p = ShareSDKPlatforms.wechatSession;
  166. break;
  167. case SharePlateform.wechatTimeline:
  168. p = ShareSDKPlatforms.wechatTimeline;
  169. break;
  170. case SharePlateform.qq:
  171. p = ShareSDKPlatforms.qq;
  172. break;
  173. case SharePlateform.qqZone:
  174. p = ShareSDKPlatforms.qZone;
  175. break;
  176. case SharePlateform.sina:
  177. p = ShareSDKPlatforms.sina;
  178. break;
  179. }
  180. if (model.image is List && (model.image as List).length > 1) {
  181. List<String> paths = await ImageDownloadUtil.download(model.image);
  182. ShareExtend.shareMultiple(
  183. paths, "image", subject: "");
  184. return;
  185. }
  186. SharesdkPlugin.share(p, params, (SSDKResponseState state, Map userdata,
  187. Map contentEntity, SSDKError error) {
  188. Logger.debug('${state}, ${error.rawData}');
  189. });
  190. }
  191. // 多图分享
  192. _shareMultipleImages() async {
  193. // List<Asset> assetList = await MultiImagePicker.pickImages(maxImages: 5);
  194. // var imageList = List<String>();
  195. // for (var asset in assetList) {
  196. // String path =
  197. // await _writeByteToImageFile(await asset.getByteData(quality: 30));
  198. // imageList.add(path);
  199. // }
  200. // ShareExtend.shareMultiple(imageList, "image", subject: "share muti image");
  201. }
  202. }