初始化
This commit is contained in:
@@ -0,0 +1,202 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hgdj/assets_tool/app_colors.dart';
|
||||
import 'package:hgdj/assets_tool/images.dart';
|
||||
import 'package:hgdj/config/config.dart';
|
||||
import 'package:hgdj/hj_model/user/user_info_model.dart';
|
||||
import 'package:hgdj/hj_utils/screen.dart';
|
||||
import 'package:hgdj/tools_base/toast.dart';
|
||||
import 'package:hgdj/tools_base/widget/common_dialog.dart';
|
||||
import 'package:hgdj/tools_base/widget/net_image_widget.dart';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
|
||||
import '../../config/address.dart';
|
||||
import '../../hj_model/video_model.dart';
|
||||
import '../../hj_utils/image_util.dart';
|
||||
import '../../tools_base/global_store/store.dart';
|
||||
|
||||
///分享二维码对话框
|
||||
class ShareMediaDialog extends StatefulWidget {
|
||||
final VideoModel? videoModel;
|
||||
final bool needDecrypt; //封面是否需要解密(直播封面不加密,传 false)
|
||||
|
||||
const ShareMediaDialog({
|
||||
super.key,
|
||||
this.videoModel,
|
||||
this.needDecrypt = true,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ShareMediaDialog> createState() => _ShareMediaDialogState();
|
||||
}
|
||||
|
||||
class _ShareMediaDialogState extends State<ShareMediaDialog> {
|
||||
final _shotKey = GlobalKey(); //保存图片时截取的范围
|
||||
|
||||
UserInfoModel? get _me => globalStore.meInfo;
|
||||
|
||||
//推广链接:弹窗打开时取一次即可(二维码/复制都用它)
|
||||
late final String _shareUrl = _me?.promoteURL ?? "";
|
||||
|
||||
/// 复制链接
|
||||
void _onCopyLink() {
|
||||
if (_shareUrl.isEmpty) {
|
||||
showToast("链接生成错误");
|
||||
return;
|
||||
}
|
||||
Clipboard.setData(ClipboardData(text: _shareUrl));
|
||||
showToast("复制成功,快去分享吧");
|
||||
Get.back();
|
||||
}
|
||||
|
||||
/// 保存图片(必须等截图完成再关弹窗,否则 _shotKey 对应的 widget 已销毁)
|
||||
Future<void> _onSaveImg() async {
|
||||
final ok = await ImageUtil.saveWidgetToAlbum(_shotKey);
|
||||
showToast(ok ? "保存成功,快去分享吧" : "保存失败,请重试");
|
||||
if (mounted) Get.back(); // 保存期间弹窗可能已被关掉(连点/点了复制),别多 pop 一层
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CommonDialog(
|
||||
padding: EdgeInsets.zero,
|
||||
child: RepaintBoundary(
|
||||
key: _shotKey,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 23, vertical: 32),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
//app 图标 + 名称 + 标语
|
||||
Row(
|
||||
children: [
|
||||
Image.asset('ic_launcher.webp'.commonImgPath,
|
||||
width: 48.w, height: 48.w),
|
||||
10.w.sizeBoxW,
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
Config.appName,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: .9),
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 14),
|
||||
),
|
||||
4.sizeBoxH,
|
||||
Text("亚洲最火成人网站",
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: .55),
|
||||
fontSize: 10)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
18.sizeBoxH,
|
||||
//视频封面
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 27),
|
||||
child: NetworkImageLoader(
|
||||
width: double.infinity,
|
||||
imageUrl: widget.videoModel?.cover ?? "",
|
||||
fit: BoxFit.fitHeight,
|
||||
encrypt: widget.needDecrypt,
|
||||
),
|
||||
),
|
||||
18.sizeBoxH,
|
||||
//二维码 + 邀请码 + 官网地址
|
||||
SizedBox(
|
||||
height: 94,
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 94,
|
||||
height: 94,
|
||||
padding: const EdgeInsets.all(2),
|
||||
color: Colors.white,
|
||||
child: QrImageView(
|
||||
data: _shareUrl, padding: EdgeInsets.zero),
|
||||
),
|
||||
16.sizeBoxW,
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"邀请码${_me?.promotionCode ?? ""}",
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.white.withValues(alpha: .9)),
|
||||
),
|
||||
20.sizeBoxH,
|
||||
Text(
|
||||
'官方网址:${Address.groundUrl ?? ""}',
|
||||
maxLines: 2,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white.withValues(alpha: .55)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
24.sizeBoxH,
|
||||
//底部两个按钮
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _button(
|
||||
"复制链接",
|
||||
bgColor: Colors.white.withValues(alpha: .1),
|
||||
textColor: const Color(0xff989898),
|
||||
onTap: _onCopyLink,
|
||||
),
|
||||
),
|
||||
16.sizeBoxW,
|
||||
Expanded(
|
||||
child: _button(
|
||||
"保存图片",
|
||||
bgColor: AppColors.actionRed,
|
||||
textColor: Colors.white,
|
||||
onTap: _onSaveImg,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _button(String text,
|
||||
{required Color bgColor,
|
||||
required Color textColor,
|
||||
required VoidCallback onTap}) {
|
||||
return InkWell(
|
||||
enableFeedback: false,
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
height: 44,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
color: bgColor,
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
fontSize: 16, color: textColor, fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user