talk_share_dialog.dart 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. children: [
  113. Text(
  114. '发送至',
  115. style: TextStyle(
  116. fontSize: 14.sp,
  117. color: ColorName.secondaryTextColor),
  118. ),
  119. SizedBox(height: 8.h),
  120. Row(
  121. children: [
  122. _buildShareItem(StringName.dialogSendFriend.tr,
  123. Assets.images.iconWx.provider(), () {
  124. callback(shareType.value, ShareTo.qq,
  125. getFileName(), tag);
  126. }),
  127. _buildShareItem(StringName.dialogSendFriend.tr,
  128. Assets.images.iconQq.provider(), () {
  129. callback(shareType.value, ShareTo.qq,
  130. getFileName(), tag);
  131. }),
  132. ],
  133. )
  134. ],
  135. ),
  136. ],
  137. ),
  138. ),
  139. ));
  140. }
  141. Widget _buildShareTypeItem(String title, ImageProvider imageProvider,
  142. bool isCheck, void Function() onTap) {
  143. return GestureDetector(
  144. onTap: onTap,
  145. child: Container(
  146. padding: EdgeInsets.only(top: 14.h, bottom: 12.h),
  147. decoration: isCheck
  148. ? BoxDecoration(
  149. color: '#E7E9F6'.toColor(),
  150. border: Border.all(color: ColorName.colorPrimary, width: 2),
  151. borderRadius: BorderRadius.circular(8),
  152. )
  153. : BoxDecoration(
  154. color: '#F6F5F8'.toColor(),
  155. borderRadius: BorderRadius.circular(8),
  156. ),
  157. child: Column(
  158. children: [
  159. Image(image: imageProvider, width: 24.w, height: 24.w),
  160. SizedBox(width: 4.h),
  161. Text(title,
  162. style: TextStyle(
  163. fontSize: 14.sp, color: ColorName.primaryTextColor)),
  164. ],
  165. ),
  166. ),
  167. );
  168. }
  169. Widget _buildShareItem(
  170. String itemName, ImageProvider imageProvider, void Function() onTap) {
  171. return Container(
  172. margin: EdgeInsets.symmetric(horizontal: 10.w),
  173. child: GestureDetector(
  174. onTap: onTap,
  175. child: Column(
  176. children: [
  177. Image(image: imageProvider, width: 40.w, height: 40.w),
  178. SizedBox(height: 6.h),
  179. Text(itemName,
  180. style: TextStyle(
  181. fontSize: 14.sp, color: ColorName.secondaryTextColor)),
  182. ],
  183. ),
  184. ),
  185. );
  186. }
  187. enum ShareTalkType { summary, original }
  188. enum ShareTo { wechat, qq, ios }