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

share_alert.dart 5.3 KiB

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