talk_share_dialog.dart 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. Text(
  81. '发送至',
  82. style: TextStyle(
  83. fontSize: 14.sp, color: ColorName.secondaryTextColor),
  84. ),
  85. SizedBox(height: 8.h),
  86. Row(
  87. children: [
  88. _buildShareItem(StringName.dialogSendFriend.tr,
  89. Assets.images.iconWx.provider(), () {
  90. callback(shareType.value, ShareTo.wechat, getFileName(),
  91. tag);
  92. }),
  93. _buildShareItem(StringName.dialogSendFriend.tr,
  94. Assets.images.iconQq.provider(), () {
  95. callback(
  96. shareType.value, ShareTo.qq, getFileName(), tag);
  97. }),
  98. ],
  99. )
  100. ],
  101. ),
  102. ),
  103. ));
  104. }
  105. Widget _buildShareTypeItem(String title, ImageProvider imageProvider,
  106. bool isCheck, void Function() onTap) {
  107. return GestureDetector(
  108. onTap: onTap,
  109. child: Container(
  110. padding: EdgeInsets.only(top: 14.h, bottom: 12.h),
  111. decoration: isCheck
  112. ? BoxDecoration(
  113. color: '#E7E9F6'.toColor(),
  114. border: Border.all(color: ColorName.colorPrimary, width: 2),
  115. borderRadius: BorderRadius.circular(8),
  116. )
  117. : BoxDecoration(
  118. color: '#F6F5F8'.toColor(),
  119. borderRadius: BorderRadius.circular(8),
  120. ),
  121. child: Column(
  122. children: [
  123. Image(image: imageProvider, width: 24.w, height: 24.w),
  124. SizedBox(width: 4.h),
  125. Text(title,
  126. style: TextStyle(
  127. fontSize: 14.sp, color: ColorName.primaryTextColor)),
  128. ],
  129. ),
  130. ),
  131. );
  132. }
  133. Widget _buildShareItem(
  134. String itemName, ImageProvider imageProvider, void Function() onTap) {
  135. return Container(
  136. margin: EdgeInsets.symmetric(horizontal: 10.w),
  137. child: GestureDetector(
  138. onTap: onTap,
  139. child: Column(
  140. children: [
  141. Image(image: imageProvider, width: 40.w, height: 40.w),
  142. SizedBox(height: 6.h),
  143. Text(itemName,
  144. style: TextStyle(
  145. fontSize: 14.sp, color: ColorName.secondaryTextColor)),
  146. ],
  147. ),
  148. ),
  149. );
  150. }
  151. enum ShareTalkType { summary, original }
  152. enum ShareTo { wechat, qq }