talk_share_dialog.dart 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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, tag);
  84. },
  85. child: Container(
  86. margin: EdgeInsets.only(top: 8.h),
  87. decoration: BoxDecoration(
  88. borderRadius: BorderRadius.circular(8),
  89. gradient: LinearGradient(
  90. colors: [
  91. '#6177F2'.toColor(),
  92. '#8B9DFF'.toColor()
  93. ],
  94. begin: Alignment.centerLeft,
  95. end: Alignment.centerRight,
  96. stops: const [0, 1.0],
  97. ),
  98. ),
  99. // width: 240.w,
  100. height: 48.w,
  101. child: Center(
  102. child: Text(
  103. "分享",
  104. style: TextStyle(
  105. fontSize: 16.sp, color: ColorName.white),
  106. ),
  107. ),
  108. ),
  109. )
  110. : Column(
  111. children: [
  112. Text(
  113. '发送至',
  114. style: TextStyle(
  115. fontSize: 14.sp,
  116. color: ColorName.secondaryTextColor),
  117. ),
  118. SizedBox(height: 8.h),
  119. Row(
  120. children: [
  121. _buildShareItem(StringName.dialogSendFriend.tr,
  122. Assets.images.iconWx.provider(), () {
  123. callback(
  124. shareType.value, ShareTo.wechat, tag);
  125. }),
  126. _buildShareItem(StringName.dialogSendFriend.tr,
  127. Assets.images.iconQq.provider(), () {
  128. callback(shareType.value, ShareTo.qq, tag);
  129. }),
  130. ],
  131. )
  132. ],
  133. ),
  134. ],
  135. ),
  136. ),
  137. ));
  138. }
  139. Widget _buildShareTypeItem(String title, ImageProvider imageProvider,
  140. bool isCheck, void Function() onTap) {
  141. return GestureDetector(
  142. onTap: onTap,
  143. child: Container(
  144. padding: EdgeInsets.only(top: 14.h, bottom: 12.h),
  145. decoration: isCheck
  146. ? BoxDecoration(
  147. color: '#E7E9F6'.toColor(),
  148. border: Border.all(color: ColorName.colorPrimary, width: 2),
  149. borderRadius: BorderRadius.circular(8),
  150. )
  151. : BoxDecoration(
  152. color: '#F6F5F8'.toColor(),
  153. borderRadius: BorderRadius.circular(8),
  154. ),
  155. child: Column(
  156. children: [
  157. Image(image: imageProvider, width: 24.w, height: 24.w),
  158. SizedBox(width: 4.h),
  159. Text(title,
  160. style: TextStyle(
  161. fontSize: 14.sp, color: ColorName.primaryTextColor)),
  162. ],
  163. ),
  164. ),
  165. );
  166. }
  167. Widget _buildShareItem(
  168. String itemName, ImageProvider imageProvider, void Function() onTap) {
  169. return Container(
  170. margin: EdgeInsets.symmetric(horizontal: 10.w),
  171. child: GestureDetector(
  172. onTap: onTap,
  173. child: Column(
  174. children: [
  175. Image(image: imageProvider, width: 40.w, height: 40.w),
  176. SizedBox(height: 6.h),
  177. Text(itemName,
  178. style: TextStyle(
  179. fontSize: 14.sp, color: ColorName.secondaryTextColor)),
  180. ],
  181. ),
  182. ),
  183. );
  184. }
  185. enum ShareTalkType { summary, original }
  186. enum ShareTo { wechat, qq, ios }