485 lines
27 KiB
Dart
485 lines
27 KiB
Dart
import 'dart:io';
|
||
import 'dart:typed_data';
|
||
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/rendering.dart';
|
||
import 'package:flutter/services.dart';
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
||
import 'package:path_provider/path_provider.dart';
|
||
import 'package:qr_flutter/qr_flutter.dart';
|
||
import 'dart:ui' as ui;
|
||
import '../../circle_app/home/logic.dart';
|
||
import '../../circle_app/userinfo/logic.dart';
|
||
import '../../utils/cache_img.dart';
|
||
import '../../utils/util.dart';
|
||
import '../Widgets/tag_widget.dart';
|
||
import '../colors/app_color.dart';
|
||
import 'package:fluwx/fluwx.dart' as fluwx;
|
||
|
||
class VideoShareDialog extends StatefulWidget {
|
||
String url;
|
||
String content;
|
||
VideoShareDialog(
|
||
{super.key,
|
||
required this.url,required this.content});
|
||
@override
|
||
_VideoShareDialogState createState() => new _VideoShareDialogState();
|
||
|
||
}
|
||
|
||
class _VideoShareDialogState extends State<VideoShareDialog> {
|
||
// TODO: add state variables and methods
|
||
HomeLogic logic = Get.find<HomeLogic>();
|
||
|
||
GlobalKey _globalKey = GlobalKey();
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
// TODO: add widget build method
|
||
return Scaffold(
|
||
backgroundColor: Colors.transparent,
|
||
body: Container(
|
||
child: Column(
|
||
children: [
|
||
Expanded(child: Container()),
|
||
Container(
|
||
width: Get.width - 40.sp,
|
||
child: SingleChildScrollView(
|
||
child: RepaintBoundary(
|
||
key: _globalKey,
|
||
child: Container(
|
||
decoration: BoxDecoration(
|
||
image: DecorationImage(
|
||
image: AssetImage(getCircleImage("open_vip_bg")),
|
||
fit: BoxFit.fill,
|
||
),
|
||
),
|
||
child: Column(
|
||
children: [
|
||
Container(
|
||
width: Get.width,
|
||
height: 65.sp,
|
||
margin: EdgeInsets.only(
|
||
left: 15.sp, top: 20.sp, right: 15.sp),
|
||
child: Row(
|
||
children: [
|
||
Center(
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
Container(
|
||
width: 47.sp,
|
||
height: 47.sp,
|
||
decoration: const BoxDecoration(
|
||
shape: BoxShape.circle,
|
||
),
|
||
),
|
||
SizedBox(
|
||
width: 46.sp,
|
||
height: 46.sp,
|
||
child: _buildAvatar1(logic),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
Expanded(
|
||
child: Container(
|
||
padding: EdgeInsets.only(left: 10.sp),
|
||
child: Column(
|
||
crossAxisAlignment:
|
||
CrossAxisAlignment.start,
|
||
children: [
|
||
_buildNameRow(logic),
|
||
SizedBox(height: 10.sp),
|
||
_buildInfoRow(logic),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
Image.asset(
|
||
getBaseImage("ic_launcher"),
|
||
width: 60.sp,
|
||
height: 60.sp,
|
||
)
|
||
],
|
||
),
|
||
),
|
||
Container(
|
||
height: 300.sp,
|
||
width: Get.width,
|
||
margin: EdgeInsets.only(
|
||
left: 10.sp,
|
||
right: 10.sp,
|
||
top: 10.sp,
|
||
bottom: 5.sp),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Container(
|
||
margin: EdgeInsets.only(bottom: 5.sp),
|
||
child: Text(
|
||
widget.content,style: TextStyle(color: Colors.white,fontSize: 15.sp),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: ClipRRect(
|
||
borderRadius: BorderRadius.circular(6.sp),
|
||
child: Image.network(
|
||
widget.url,
|
||
fit: BoxFit.contain,
|
||
)),
|
||
),
|
||
|
||
],
|
||
),
|
||
),
|
||
Container(
|
||
// height: 90.sp,
|
||
// color: Color(0xFF334141),
|
||
alignment: Alignment.center,
|
||
// color: Colors.yellow,
|
||
// width: Get.width-40.sp,
|
||
margin:
|
||
EdgeInsets.only(bottom: 15.sp, top: 10.sp),
|
||
padding:
|
||
EdgeInsets.only(left: 15.sp, right: 15.sp),
|
||
child: Row(
|
||
children: [
|
||
Expanded(
|
||
child: Container(
|
||
// color: Colors.red,
|
||
child: Column(
|
||
crossAxisAlignment:
|
||
CrossAxisAlignment.start,
|
||
children: [
|
||
Container(
|
||
// color: Colors.blue,
|
||
child: Row(
|
||
children: [
|
||
Text(
|
||
'专属邀请码',
|
||
style: TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 18.sp),
|
||
),
|
||
SizedBox(
|
||
width: 8.sp,
|
||
),
|
||
Container(
|
||
alignment: Alignment.center,
|
||
padding: EdgeInsets.only(
|
||
left: 10.sp,
|
||
right: 10.sp),
|
||
height: 25.sp,
|
||
decoration: BoxDecoration(
|
||
// color: Color(0xFFDC5BFD),
|
||
gradient: AppColor
|
||
.mainVerLinearGradient,
|
||
borderRadius:
|
||
BorderRadius.circular(
|
||
12.5.sp)),
|
||
child: Text(
|
||
logic.inviteCode,
|
||
style: TextStyle(
|
||
color: Colors.black,
|
||
fontSize: 12.sp),
|
||
),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
Container(
|
||
margin: EdgeInsets.only(top: 10.sp),
|
||
width: Get.width - 200.sp,
|
||
child: Text(
|
||
'扫码或长按识别下载APP,认识更多小众圈子里的人,给生活带来更多乐趣~',
|
||
style: TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 15.sp)),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
),
|
||
// Image.asset(getBaseImage("ic_launcher"),width: 80.sp,height: 80.sp,)
|
||
Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
Container(
|
||
color: Colors.white,
|
||
width: 90.sp,
|
||
height: 90.sp,
|
||
),
|
||
QrImageView(
|
||
data: logic.link +
|
||
'#code=${logic.inviteCode}',
|
||
padding: EdgeInsets.zero,
|
||
version: QrVersions.auto,
|
||
size: 80.sp,
|
||
gapless: false,
|
||
// backgroundColor: Colors.black,
|
||
)
|
||
],
|
||
)
|
||
],
|
||
),
|
||
)
|
||
],
|
||
),
|
||
))),
|
||
),
|
||
SafeArea(
|
||
top: false,
|
||
bottom: false,
|
||
child: Container(
|
||
height:
|
||
164.sp,
|
||
width: Get.width,
|
||
color: Color(0xFF292247),
|
||
child: Column(
|
||
children: [
|
||
Expanded(
|
||
child: Container(
|
||
padding: EdgeInsets.only(
|
||
top: 15.sp, left: 15.sp, right: 15.sp),
|
||
alignment: Alignment.center,
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
shareAction('wx', '微信', () {
|
||
shareWxData(1);
|
||
}),
|
||
shareAction('wxq', '朋友圈', () {
|
||
shareWxData(2);
|
||
}),
|
||
shareAction('save', '复制邀请链接', () {
|
||
copyInviteText(logic.model!.nickname!);
|
||
}),
|
||
// shareAction('wb', '复制链接', () {
|
||
// copyInviteText(logic.name);
|
||
// }),
|
||
|
||
shareAction('hb', '保存邀请海报', () {
|
||
_saveLocalImage();
|
||
}),
|
||
],
|
||
),
|
||
)),
|
||
Container(
|
||
height: 1.sp,
|
||
color: Color(0x33FFFFFF),
|
||
),
|
||
GestureDetector(
|
||
behavior: HitTestBehavior.opaque,
|
||
onTap: () {
|
||
Get.back();
|
||
},
|
||
child: Container(
|
||
height: 67.sp,
|
||
alignment: Alignment.center,
|
||
child: Text(
|
||
'取消',
|
||
style:
|
||
TextStyle(color: Colors.white, fontSize: 14.sp),
|
||
),
|
||
),
|
||
)
|
||
],
|
||
),
|
||
))
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildAvatar1(HomeLogic logic) {
|
||
return ClipOval(
|
||
child: GestureDetector(
|
||
onTap: () {
|
||
if (logic.model != null) {
|
||
var imgList = <String>[];
|
||
imgList.add(logic.model!.avatar!);
|
||
// Get.toNamed(AppRoutes.Swiper,arguments:imgList);
|
||
// Get.toNamed(AppRoutes.Swiper, arguments: {
|
||
// 'imaglist': imgList,
|
||
// 'index': 0
|
||
// });
|
||
}
|
||
},
|
||
child: logic.model == null
|
||
? SizedBox(
|
||
width: 63.sp,
|
||
height: 63.sp,
|
||
)
|
||
: CachedImg(
|
||
fit: BoxFit.cover,
|
||
imageUrl: logic.model!.avatar!,
|
||
width: 63.sp,
|
||
height: 63.sp,
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildNameRow(HomeLogic logic) {
|
||
int gender = logic.model!.gender!;
|
||
int role = logic.model!.role!;
|
||
int age = logic.model!.age!;
|
||
int orientation = logic.model!.orientation!;
|
||
|
||
String ageMsg = getAgeCOntent(gender, age, role, orientation);
|
||
return Container(
|
||
margin: EdgeInsets.only(top: 6.sp),
|
||
child: Row(
|
||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Text(
|
||
logic.model!.nickname!,
|
||
style: TextStyle(
|
||
color: const Color.fromRGBO(247, 250, 250, 1.0),
|
||
fontSize: 16.sp,
|
||
),
|
||
),
|
||
SizedBox(
|
||
width: 4.sp,
|
||
),
|
||
Container(
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(17),
|
||
gradient: sexBgGradient(gender),
|
||
),
|
||
padding: EdgeInsets.only(
|
||
top: 2.sp, bottom: 2.sp, left: 10.sp, right: 10.sp),
|
||
child: Text(
|
||
ageMsg,
|
||
style: TextStyle(
|
||
color: sexBgColor(gender),
|
||
fontSize: 10.sp,
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildInfoRow(HomeLogic logic) {
|
||
return Row(
|
||
children: [
|
||
Text('邀请您加入',
|
||
style: TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 12.sp,
|
||
)),
|
||
Text('【微乐园APP】',
|
||
style: TextStyle(
|
||
color: AppColor.mainColor,
|
||
fontSize: 14.sp,
|
||
fontWeight: FontWeight.bold)),
|
||
],
|
||
);
|
||
}
|
||
|
||
shareAction(String img, String name, GestureTapCallback onTap) {
|
||
return GestureDetector(
|
||
onTap: onTap,
|
||
child: Container(
|
||
child: Column(
|
||
children: [
|
||
Image.asset(
|
||
getMineImage(img),
|
||
width: 40.sp,
|
||
),
|
||
SizedBox(
|
||
height: 10.sp,
|
||
),
|
||
Text(
|
||
name,
|
||
style: TextStyle(color: Colors.white, fontSize: 12.sp),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
_saveLocalImage() async {
|
||
RenderRepaintBoundary boundary =
|
||
_globalKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
|
||
ui.Image image =
|
||
await boundary.toImage(pixelRatio: 1.0);
|
||
ByteData? byteData =
|
||
await (image.toByteData(format: ui.ImageByteFormat.png));
|
||
if (byteData != null) {
|
||
final result =
|
||
await ImageGallerySaver.saveImage(byteData.buffer.asUint8List());
|
||
print(result);
|
||
// isSuccess
|
||
if (result['isSuccess']) {
|
||
showOKToast('保存成功');
|
||
} else {
|
||
showOKToast('保存失败,请检查相册权限是否开启');
|
||
}
|
||
}
|
||
}
|
||
|
||
copyInviteText(
|
||
String username,
|
||
) {
|
||
String linkStr = logic.link.replaceAll('https://', '');
|
||
|
||
Clipboard.setData(ClipboardData(
|
||
text:
|
||
'【${username}】邀请你加入“微乐园”,邀请码为${logic.inviteCode},点击进入${logic.link}'
|
||
'这是一款专为各种特色小众圈子爱好者打造的交友平台,资质齐全,安全正规。'
|
||
'在这里,能看到很多没听说过的圈子,也能发现很多为数不多的真实情怀,还能见证小众亚文化在生活方式上的新体验。真实、安全、私密、走心,我和很多圈友都在玩哦~'));
|
||
showOKToast('您已成功复制分享链接,前往对应平台粘贴发送即可~');
|
||
}
|
||
|
||
/**
|
||
* 分享图片到微信,
|
||
* file=本地路径
|
||
* url=网络地址
|
||
* asset=内置在app的资源图片
|
||
* scene=分享场景,1好友会话,2朋友圈,3收藏
|
||
*/
|
||
void shareWxData(int scene) async {
|
||
SmartDialog.showLoading(msg: '正在生成分享图片...');
|
||
RenderRepaintBoundary boundary =
|
||
_globalKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
|
||
ui.Image image =
|
||
await boundary.toImage(pixelRatio: 1.0);
|
||
ByteData? byteData =
|
||
await (image.toByteData(format: ui.ImageByteFormat.png));
|
||
String filePath = '';
|
||
if (byteData != null) {
|
||
Uint8List pngBytes = byteData!.buffer.asUint8List();
|
||
Directory directory = await getApplicationDocumentsDirectory();
|
||
filePath = '${directory.path}/widget_image.png';
|
||
File imageFile = File(filePath);
|
||
imageFile.writeAsBytesSync(pngBytes);
|
||
}
|
||
SmartDialog.dismiss();
|
||
fluwx.WeChatScene wxScene = fluwx.WeChatScene.SESSION;
|
||
if (scene == 2) {
|
||
wxScene = fluwx.WeChatScene.TIMELINE;
|
||
}
|
||
fluwx.WeChatShareImageModel? model;
|
||
|
||
if (filePath.isNotEmpty) {
|
||
model = fluwx.WeChatShareImageModel(
|
||
fluwx.WeChatImage.file(File(filePath)),
|
||
title: '',
|
||
description: '',
|
||
scene: wxScene);
|
||
}
|
||
if (model != null) {
|
||
fluwx.shareToWeChat(model!);
|
||
}
|
||
}
|
||
}
|