| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- import 'package:electronic_assistant/resource/assets.gen.dart';
- import 'package:electronic_assistant/resource/string.gen.dart';
- import 'package:electronic_assistant/utils/expand.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
- import 'package:get/get.dart';
- import '../resource/colors.gen.dart';
- typedef TalkShareCallback = void Function(ShareTalkType shareType,
- ShareTo shareTo, String fileName, String dialogTag);
- void showTalkShareDialog(String? title,
- {required TalkShareCallback callback, List<ShareTalkType>? shareToType}) {
- const String tag = 'showTalkShareDialog';
- Rx<ShareTalkType> shareType = ShareTalkType.summary.obs;
- String getFileName() {
- if (shareType.value == ShareTalkType.summary) {
- return '[${StringName.talkTabSummary.tr}] $title.txt';
- } else if (shareType.value == ShareTalkType.mindMap) {
- return '$title.png';
- } else {
- return '[${StringName.talkTabOriginal.tr}] $title.txt';
- }
- }
- SmartDialog.show(
- tag: tag,
- maskColor: Colors.black54,
- alignment: const Alignment(0.0, 0.94),
- builder: (_) => Container(
- width: 336.w,
- padding: EdgeInsets.all(16.w),
- decoration: BoxDecoration(
- color: ColorName.white,
- borderRadius: BorderRadius.circular(12),
- ),
- child: IntrinsicHeight(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- children: [
- Obx(() {
- return shareType.value == ShareTalkType.mindMap
- ? Assets.images.iconShareFilePng
- .image(width: 28.w, height: 32.w)
- : Assets.images.iconTalkTxt
- .image(width: 28.w, height: 32.w);
- }),
- SizedBox(width: 6.w),
- Expanded(child: Obx(() {
- return Text(getFileName(),
- style: TextStyle(
- fontSize: 14.sp,
- fontWeight: FontWeight.bold,
- color: ColorName.primaryTextColor));
- })),
- SizedBox(width: 18.w),
- GestureDetector(
- onTap: () {
- SmartDialog.dismiss(tag: tag);
- },
- child: Assets.images.iconTalkShareClose
- .image(width: 28.w, height: 28.w),
- ),
- ],
- ),
- SizedBox(height: 12.h),
- Divider(color: '#F6F6F6'.toColor(), height: 1.h),
- SizedBox(height: 20.h),
- Obx(() {
- final type = shareToType ?? getDefaultShareType();
- return Row(
- children: [
- for (int i = 0; i < type.length; i++) ...[
- Expanded(
- child: _buildShareTypeItem(
- _getTitle(
- (shareToType ?? getDefaultShareType())[i]),
- _getIconProvider(
- (shareToType ?? getDefaultShareType())[i]),
- shareType.value ==
- (shareToType ?? getDefaultShareType())[i],
- () {
- shareType.value =
- (shareToType ?? getDefaultShareType())[i];
- },
- ),
- ),
- if (i < type.length - 1)
- SizedBox(width: 8.w), // Add gap between items
- ],
- ],
- );
- }),
- SizedBox(height: 16.h),
- GetPlatform.isIOS
- ? GestureDetector(
- onTap: () {
- callback(shareType.value, ShareTo.ios,
- getFileName(), tag);
- },
- child: Container(
- margin: EdgeInsets.only(top: 8.h),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(8),
- gradient: LinearGradient(
- colors: [
- '#6177F2'.toColor(),
- '#8B9DFF'.toColor()
- ],
- begin: Alignment.centerLeft,
- end: Alignment.centerRight,
- stops: const [0, 1.0],
- ),
- ),
- // width: 240.w,
- height: 48.w,
- child: Center(
- child: Text(
- "分享",
- style: TextStyle(
- fontSize: 16.sp, color: ColorName.white),
- ),
- ),
- ),
- )
- : Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- '发送至',
- style: TextStyle(
- fontSize: 14.sp,
- color: ColorName.secondaryTextColor),
- ),
- SizedBox(height: 8.h),
- Row(
- children: [
- _buildShareItem(StringName.dialogSendFriend.tr,
- Assets.images.iconWx.provider(), () {
- callback(shareType.value, ShareTo.wechat,
- getFileName(), tag);
- }),
- _buildShareItem(StringName.dialogSendFriend.tr,
- Assets.images.iconQq.provider(), () {
- callback(shareType.value, ShareTo.qq,
- getFileName(), tag);
- }),
- ],
- )
- ],
- ),
- ],
- ),
- ),
- ));
- }
- Widget _buildShareTypeItem(String title, ImageProvider imageProvider,
- bool isCheck, void Function() onTap) {
- return GestureDetector(
- onTap: onTap,
- child: Container(
- padding: EdgeInsets.only(top: 14.h, bottom: 12.h),
- decoration: isCheck
- ? BoxDecoration(
- color: '#E7E9F6'.toColor(),
- border: Border.all(color: ColorName.colorPrimary, width: 2),
- borderRadius: BorderRadius.circular(8),
- )
- : BoxDecoration(
- color: '#F6F5F8'.toColor(),
- borderRadius: BorderRadius.circular(8),
- ),
- child: Column(
- children: [
- Image(image: imageProvider, width: 24.w, height: 24.w),
- SizedBox(width: 4.h),
- Text(title,
- style: TextStyle(
- fontSize: 14.sp, color: ColorName.primaryTextColor)),
- ],
- ),
- ),
- );
- }
- Widget _buildShareItem(
- String itemName, ImageProvider imageProvider, void Function() onTap) {
- return Container(
- margin: EdgeInsets.symmetric(horizontal: 10.w),
- child: GestureDetector(
- onTap: onTap,
- child: Column(
- children: [
- Image(image: imageProvider, width: 40.w, height: 40.w),
- SizedBox(height: 6.h),
- Text(itemName,
- style: TextStyle(
- fontSize: 14.sp, color: ColorName.secondaryTextColor)),
- ],
- ),
- ),
- );
- }
- String _getTitle(ShareTalkType type) {
- switch (type) {
- case ShareTalkType.summary:
- return StringName.talkTabSummary.tr;
- case ShareTalkType.mindMap:
- return StringName.talkMindMap.tr;
- case ShareTalkType.original:
- return StringName.talkTabOriginal.tr;
- default:
- return '';
- }
- }
- ImageProvider _getIconProvider(ShareTalkType type) {
- switch (type) {
- case ShareTalkType.summary:
- return Assets.images.iconTalkShareSummary.provider();
- case ShareTalkType.mindMap:
- return Assets.images.iconTalkMindMap.provider();
- case ShareTalkType.original:
- return Assets.images.iconTalkShareOriginal.provider();
- default:
- return const AssetImage(''); // Provide a default image if necessary
- }
- }
- List<ShareTalkType> getDefaultShareType() {
- return [ShareTalkType.summary, ShareTalkType.mindMap, ShareTalkType.original];
- }
- enum ShareTalkType { summary, mindMap, original }
- enum ShareTo { wechat, qq, ios }
|