talk_share_dialog.dart 7.7 KB

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