talk_share_dialog.dart 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import 'package:electronic_assistant/resource/assets.gen.dart';
  2. import 'package:electronic_assistant/resource/string.gen.dart';
  3. import 'package:electronic_assistant/utils/expand.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_screenutil/flutter_screenutil.dart';
  7. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  8. import 'package:get/get.dart';
  9. import '../resource/colors.gen.dart';
  10. typedef TalkShareCallback = void Function(ShareTalkType shareType,
  11. ShareTo shareTo, String fileName, String dialogTag);
  12. void showTalkShareDialog(String? title,
  13. {required TalkShareCallback callback, List<ShareTalkType>? shareToType}) {
  14. const String tag = 'showTalkShareDialog';
  15. Rx<ShareTalkType> shareType = ShareTalkType.summary.obs;
  16. String getFileName() {
  17. if (shareType.value == ShareTalkType.summary) {
  18. return '[${StringName.talkTabSummary.tr}] $title.txt';
  19. } else if (shareType.value == ShareTalkType.mindMap) {
  20. return '$title.png';
  21. } else {
  22. return '[${StringName.talkTabOriginal.tr}] $title.txt';
  23. }
  24. }
  25. SmartDialog.show(
  26. tag: tag,
  27. maskColor: Colors.black54,
  28. alignment: const Alignment(0.0, 0.94),
  29. builder: (_) => Container(
  30. width: 336.w,
  31. padding: EdgeInsets.all(16.w),
  32. decoration: BoxDecoration(
  33. color: ColorName.white,
  34. borderRadius: BorderRadius.circular(12),
  35. ),
  36. child: IntrinsicHeight(
  37. child: Column(
  38. crossAxisAlignment: CrossAxisAlignment.start,
  39. children: [
  40. Row(
  41. children: [
  42. Obx(() {
  43. return shareType.value == ShareTalkType.mindMap
  44. ? Assets.images.iconShareFilePng
  45. .image(width: 28.w, height: 32.w)
  46. : Assets.images.iconTalkTxt
  47. .image(width: 28.w, height: 32.w);
  48. }),
  49. SizedBox(width: 6.w),
  50. Expanded(child: Obx(() {
  51. return Text(getFileName(),
  52. style: TextStyle(
  53. fontSize: 14.sp,
  54. fontWeight: FontWeight.bold,
  55. color: ColorName.primaryTextColor));
  56. })),
  57. SizedBox(width: 18.w),
  58. GestureDetector(
  59. onTap: () {
  60. SmartDialog.dismiss(tag: tag);
  61. },
  62. child: Assets.images.iconTalkShareClose
  63. .image(width: 28.w, height: 28.w),
  64. ),
  65. ],
  66. ),
  67. SizedBox(height: 12.h),
  68. Divider(color: '#F6F6F6'.toColor(), height: 1.h),
  69. SizedBox(height: 20.h),
  70. Obx(() {
  71. final type = shareToType ?? getDefaultShareType();
  72. return Row(
  73. children: [
  74. for (int i = 0; i < type.length; i++) ...[
  75. Expanded(
  76. child: _buildShareTypeItem(
  77. _getTitle(
  78. (shareToType ?? getDefaultShareType())[i]),
  79. _getIconProvider(
  80. (shareToType ?? getDefaultShareType())[i]),
  81. shareType.value ==
  82. (shareToType ?? getDefaultShareType())[i],
  83. () {
  84. shareType.value =
  85. (shareToType ?? getDefaultShareType())[i];
  86. },
  87. ),
  88. ),
  89. if (i < type.length - 1)
  90. SizedBox(width: 8.w), // Add gap between items
  91. ],
  92. ],
  93. );
  94. }),
  95. SizedBox(height: 16.h),
  96. GetPlatform.isIOS
  97. ? GestureDetector(
  98. onTap: () {
  99. callback(shareType.value, ShareTo.ios,
  100. getFileName(), tag);
  101. },
  102. child: Container(
  103. margin: EdgeInsets.only(top: 8.h),
  104. decoration: BoxDecoration(
  105. borderRadius: BorderRadius.circular(8),
  106. gradient: LinearGradient(
  107. colors: [
  108. '#6177F2'.toColor(),
  109. '#8B9DFF'.toColor()
  110. ],
  111. begin: Alignment.centerLeft,
  112. end: Alignment.centerRight,
  113. stops: const [0, 1.0],
  114. ),
  115. ),
  116. // width: 240.w,
  117. height: 48.w,
  118. child: Center(
  119. child: Text(
  120. "分享",
  121. style: TextStyle(
  122. fontSize: 16.sp, color: ColorName.white),
  123. ),
  124. ),
  125. ),
  126. )
  127. : Column(
  128. crossAxisAlignment: CrossAxisAlignment.start,
  129. children: [
  130. Text(
  131. '发送至',
  132. style: TextStyle(
  133. fontSize: 14.sp,
  134. color: ColorName.secondaryTextColor),
  135. ),
  136. SizedBox(height: 8.h),
  137. Row(
  138. children: [
  139. _buildShareItem(StringName.dialogSendFriend.tr,
  140. Assets.images.iconWx.provider(), () {
  141. callback(shareType.value, ShareTo.wechat,
  142. getFileName(), tag);
  143. }),
  144. _buildShareItem(StringName.dialogSendFriend.tr,
  145. Assets.images.iconQq.provider(), () {
  146. callback(shareType.value, ShareTo.qq,
  147. getFileName(), tag);
  148. }),
  149. ],
  150. )
  151. ],
  152. ),
  153. ],
  154. ),
  155. ),
  156. ));
  157. }
  158. Widget _buildShareTypeItem(String title, ImageProvider imageProvider,
  159. bool isCheck, void Function() onTap) {
  160. return GestureDetector(
  161. onTap: onTap,
  162. child: Container(
  163. padding: EdgeInsets.only(top: 14.h, bottom: 12.h),
  164. decoration: isCheck
  165. ? BoxDecoration(
  166. color: '#E7E9F6'.toColor(),
  167. border: Border.all(color: ColorName.colorPrimary, width: 2),
  168. borderRadius: BorderRadius.circular(8),
  169. )
  170. : BoxDecoration(
  171. color: '#F6F5F8'.toColor(),
  172. borderRadius: BorderRadius.circular(8),
  173. ),
  174. child: Column(
  175. children: [
  176. Image(image: imageProvider, width: 24.w, height: 24.w),
  177. SizedBox(width: 4.h),
  178. Text(title,
  179. style: TextStyle(
  180. fontSize: 14.sp, color: ColorName.primaryTextColor)),
  181. ],
  182. ),
  183. ),
  184. );
  185. }
  186. Widget _buildShareItem(
  187. String itemName, ImageProvider imageProvider, void Function() onTap) {
  188. return Container(
  189. margin: EdgeInsets.symmetric(horizontal: 10.w),
  190. child: GestureDetector(
  191. onTap: onTap,
  192. child: Column(
  193. children: [
  194. Image(image: imageProvider, width: 40.w, height: 40.w),
  195. SizedBox(height: 6.h),
  196. Text(itemName,
  197. style: TextStyle(
  198. fontSize: 14.sp, color: ColorName.secondaryTextColor)),
  199. ],
  200. ),
  201. ),
  202. );
  203. }
  204. String _getTitle(ShareTalkType type) {
  205. switch (type) {
  206. case ShareTalkType.summary:
  207. return StringName.talkTabSummary.tr;
  208. case ShareTalkType.mindMap:
  209. return StringName.talkMindMap.tr;
  210. case ShareTalkType.original:
  211. return StringName.talkTabOriginal.tr;
  212. default:
  213. return '';
  214. }
  215. }
  216. ImageProvider _getIconProvider(ShareTalkType type) {
  217. switch (type) {
  218. case ShareTalkType.summary:
  219. return Assets.images.iconTalkShareSummary.provider();
  220. case ShareTalkType.mindMap:
  221. return Assets.images.iconTalkMindMap.provider();
  222. case ShareTalkType.original:
  223. return Assets.images.iconTalkShareOriginal.provider();
  224. default:
  225. return const AssetImage(''); // Provide a default image if necessary
  226. }
  227. }
  228. List<ShareTalkType> getDefaultShareType() {
  229. return [ShareTalkType.summary, ShareTalkType.mindMap, ShareTalkType.original];
  230. }
  231. enum ShareTalkType { summary, mindMap, original }
  232. enum ShareTo { wechat, qq, ios }