基础组件库
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.
 
 
 
 
 

214 lines
6.0 KiB

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