talk_share_dialog.dart 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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(
  11. ShareTalkType shareType, ShareTo shareTo, String dialogTag);
  12. void showTalkShareDialog(String title, TalkShareCallback callback) {
  13. const String tag = 'showTalkShareDialog';
  14. Rx<ShareTalkType> shareType = ShareTalkType.summary.obs;
  15. SmartDialog.show(
  16. tag: tag,
  17. maskColor: Colors.black54,
  18. alignment: const Alignment(0.0, 0.94),
  19. builder: (_) => Container(
  20. width: 336.w,
  21. padding: EdgeInsets.all(16.w),
  22. decoration: BoxDecoration(
  23. color: ColorName.white,
  24. borderRadius: BorderRadius.circular(12),
  25. ),
  26. child: IntrinsicHeight(
  27. child: Column(
  28. crossAxisAlignment: CrossAxisAlignment.start,
  29. children: [
  30. Row(
  31. children: [
  32. Assets.images.iconTalkTxt
  33. .image(width: 28.w, height: 32.w),
  34. SizedBox(width: 6.w),
  35. Expanded(
  36. child: Text(title,
  37. style: TextStyle(
  38. fontSize: 14.sp,
  39. fontWeight: FontWeight.bold,
  40. color: ColorName.primaryTextColor))),
  41. SizedBox(width: 18.w),
  42. GestureDetector(
  43. onTap: () {
  44. SmartDialog.dismiss(tag: tag);
  45. },
  46. child: Assets.images.iconTalkShareClose
  47. .image(width: 28.w, height: 28.w),
  48. ),
  49. ],
  50. ),
  51. SizedBox(height: 12.h),
  52. Divider(color: '#F6F6F6'.toColor(), height: 1.h),
  53. SizedBox(height: 20.h),
  54. Obx(() {
  55. return Row(
  56. children: [
  57. Expanded(
  58. child: _buildShareTypeItem(
  59. StringName.talkTabSummary.tr,
  60. Assets.images.iconTalkShareSummary.provider(),
  61. shareType.value == ShareTalkType.summary, () {
  62. shareType.value = ShareTalkType.summary;
  63. })),
  64. SizedBox(width: 12.w),
  65. Expanded(
  66. child: _buildShareTypeItem(
  67. StringName.talkTabOriginal.tr,
  68. Assets.images.iconTalkShareOriginal.provider(),
  69. shareType.value == ShareTalkType.original, () {
  70. shareType.value = ShareTalkType.original;
  71. })),
  72. ],
  73. );
  74. }),
  75. SizedBox(height: 16.h),
  76. Text(
  77. '发送至',
  78. style: TextStyle(
  79. fontSize: 14.sp, color: ColorName.secondaryTextColor),
  80. ),
  81. SizedBox(height: 8.h),
  82. Row(
  83. children: [
  84. _buildShareItem(StringName.dialogSendFriend.tr,
  85. Assets.images.iconWx.provider(), () {
  86. callback(shareType.value, ShareTo.wechat, tag);
  87. }),
  88. _buildShareItem(StringName.dialogSendFriend.tr,
  89. Assets.images.iconQq.provider(), () {
  90. callback(shareType.value, ShareTo.qq, tag);
  91. }),
  92. ],
  93. )
  94. ],
  95. ),
  96. ),
  97. ));
  98. }
  99. Widget _buildShareTypeItem(String title, ImageProvider imageProvider,
  100. bool isCheck, void Function() onTap) {
  101. return GestureDetector(
  102. onTap: onTap,
  103. child: Container(
  104. padding: EdgeInsets.only(top: 14.h, bottom: 12.h),
  105. decoration: isCheck
  106. ? BoxDecoration(
  107. color: '#E7E9F6'.toColor(),
  108. border: Border.all(color: ColorName.colorPrimary, width: 2),
  109. borderRadius: BorderRadius.circular(8),
  110. )
  111. : BoxDecoration(
  112. color: '#F6F5F8'.toColor(),
  113. borderRadius: BorderRadius.circular(8),
  114. ),
  115. child: Column(
  116. children: [
  117. Image(image: imageProvider, width: 24.w, height: 24.w),
  118. SizedBox(width: 4.h),
  119. Text(title,
  120. style: TextStyle(
  121. fontSize: 14.sp, color: ColorName.primaryTextColor)),
  122. ],
  123. ),
  124. ),
  125. );
  126. }
  127. Widget _buildShareItem(
  128. String itemName, ImageProvider imageProvider, void Function() onTap) {
  129. return Container(
  130. margin: EdgeInsets.symmetric(horizontal: 10.w),
  131. child: GestureDetector(
  132. onTap: onTap,
  133. child: Column(
  134. children: [
  135. Image(image: imageProvider, width: 40.w, height: 40.w),
  136. SizedBox(height: 6.h),
  137. Text(itemName,
  138. style: TextStyle(
  139. fontSize: 14.sp, color: ColorName.secondaryTextColor)),
  140. ],
  141. ),
  142. ),
  143. );
  144. }
  145. enum ShareTalkType { summary, original }
  146. enum ShareTo { wechat, qq }