talk_share_dialog.dart 8.6 KB

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