699 lines
30 KiB
Dart
699 lines
30 KiB
Dart
import 'dart:convert';
|
||
import 'dart:io';
|
||
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/rendering.dart';
|
||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:cached_network_image/cached_network_image.dart';
|
||
|
||
import 'package:flutter/foundation.dart';
|
||
import 'package:flutter/services.dart';
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
import 'package:get/get_core/src/get_main.dart';
|
||
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
||
import 'dart:ui' as ui;
|
||
import 'package:fluwx/fluwx.dart' as fluwx;
|
||
import 'package:path_provider/path_provider.dart';
|
||
import 'package:qr_flutter/qr_flutter.dart';
|
||
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
|
||
|
||
import '../../circle_app/home/logic.dart';
|
||
import '../../circle_app/likelist/logic.dart';
|
||
import '../../circle_app/userinfo/logic.dart';
|
||
import '../../net/api.dart';
|
||
import '../../net/dio_manager.dart';
|
||
import '../../utils/cache_img.dart';
|
||
import '../../utils/util.dart';
|
||
import '../Widgets/tag_widget.dart';
|
||
import '../colors/app_color.dart';
|
||
import 'follow_me_dialog.dart';
|
||
|
||
class UserShare extends StatefulWidget {
|
||
String userImgUrl;
|
||
String userNIckName;
|
||
UserBean userInfoBean;
|
||
UserShare(
|
||
{super.key,
|
||
required this.userImgUrl,
|
||
required this.userNIckName,
|
||
required this.userInfoBean});
|
||
@override
|
||
_UserShareState createState() => new _UserShareState();
|
||
}
|
||
|
||
class _UserShareState extends State<UserShare> {
|
||
// TODO: add state variables and methods
|
||
HomeLogic logic = Get.find<HomeLogic>();
|
||
|
||
GlobalKey _globalKey = GlobalKey();
|
||
|
||
List<UserListItem> lists = [];
|
||
List<V2TimUserFullInfo> conList = [];
|
||
|
||
@override
|
||
void initState() {
|
||
// TODO: implement initState
|
||
super.initState();
|
||
loadFollowMeData();
|
||
}
|
||
|
||
@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: Stack(
|
||
children: [
|
||
ClipRRect(
|
||
borderRadius: BorderRadius.circular(6.sp),
|
||
child: Image.network(
|
||
widget.userImgUrl,
|
||
fit: BoxFit.cover,
|
||
)),
|
||
Positioned(
|
||
left: 0.sp,
|
||
bottom: 0.sp,
|
||
child: Container(
|
||
width: Get.width,
|
||
color: Colors.black
|
||
.withOpacity(0.5),
|
||
padding: EdgeInsets.only(
|
||
left: 10.sp,
|
||
bottom: 10.sp),
|
||
child: Column(
|
||
crossAxisAlignment:
|
||
CrossAxisAlignment
|
||
.start,
|
||
children: [
|
||
Row(
|
||
children: [
|
||
Text(
|
||
widget.userInfoBean?.nickname ?? "",
|
||
style: TextStyle(
|
||
color: Color.fromRGBO(247, 250, 250, 1.0),
|
||
fontSize: 14.sp,
|
||
),
|
||
),
|
||
SizedBox(width: 8.sp),
|
||
Container(
|
||
alignment: Alignment.center,
|
||
height: 18.sp,
|
||
padding: EdgeInsets.only(left: 6.sp, right: 6.sp),
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(9.sp),
|
||
gradient: sexBgGradient(widget.userInfoBean!.gender ?? 0)),
|
||
child: Text(
|
||
getAgeCOntent(widget.userInfoBean!.gender ?? 0, widget.userInfoBean!.age ?? 0,
|
||
widget.userInfoBean!.role ?? 0, widget.userInfoBean!.orientation ?? 0),
|
||
style: TextStyle(
|
||
color: sexBgColor(widget.userInfoBean!.gender ?? 0),
|
||
fontSize: 12.sp,
|
||
),
|
||
),
|
||
),
|
||
if ((widget.userInfoBean?.mark ?? 0) > 0)
|
||
SizedBox(width: 8.sp),
|
||
if ((widget.userInfoBean?.mark ?? 0) > 0)
|
||
UserTagWidget(widget.userInfoBean!.mark!),
|
||
if (widget.userInfoBean?.realAuth == 1)
|
||
SizedBox(width: 4.sp),
|
||
if (widget.userInfoBean?.realAuth == 1)
|
||
Image(
|
||
image: AssetImage(getMineImage("auth")),
|
||
height:18.sp,
|
||
),
|
||
],
|
||
),
|
||
Text(
|
||
'扫二维码,来微乐园找我',
|
||
style: TextStyle(
|
||
color: Colors.white
|
||
.withOpacity(
|
||
0.85),
|
||
fontSize: 16.sp,
|
||
fontWeight:
|
||
FontWeight
|
||
.w600),
|
||
)
|
||
],
|
||
),
|
||
))
|
||
],
|
||
),
|
||
),
|
||
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:
|
||
lists.isNotEmpty || conList.isNotEmpty ? 264.sp : 164.sp,
|
||
width: Get.width,
|
||
color: Color(0xFF292247),
|
||
child: Column(
|
||
children: [
|
||
if (lists.isNotEmpty || conList.isNotEmpty)
|
||
Container(
|
||
height: 100.sp,
|
||
child: ListView.builder(
|
||
scrollDirection: Axis.horizontal,
|
||
itemBuilder: (context, index) {
|
||
if (index == 4) {
|
||
return GestureDetector(
|
||
onTap: () {
|
||
Get.bottomSheet(
|
||
FollowMeDialog(
|
||
bean: null,
|
||
userInfoBean: widget.userInfoBean),
|
||
isScrollControlled: true,
|
||
enableDrag: false);
|
||
},
|
||
behavior: HitTestBehavior.opaque,
|
||
child: Container(
|
||
width: Get.width / 5,
|
||
child: Column(
|
||
mainAxisAlignment:
|
||
MainAxisAlignment.center,
|
||
children: [
|
||
Image.asset(
|
||
getCircleImage('share_more'),
|
||
width: 51.sp,
|
||
),
|
||
SizedBox(
|
||
height: 4.sp,
|
||
),
|
||
Text(
|
||
'更多',
|
||
style: TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 14.sp),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
var info;
|
||
if (conList.length > index) {
|
||
info = conList[index];
|
||
} else {
|
||
info = lists[index];
|
||
}
|
||
return GestureDetector(
|
||
onTap: () {
|
||
sendUserHomeCustomMsg(
|
||
info.userID ?? info.user.imId,
|
||
jsonEncode(widget.userInfoBean.toJson()),
|
||
'分享用户[${widget.userInfoBean.nickname}]的主页');
|
||
},
|
||
behavior: HitTestBehavior.opaque,
|
||
child: Container(
|
||
width: Get.width / 5,
|
||
child: Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
ClipOval(
|
||
child: Image.network(
|
||
info.faceUrl ?? info.user.avatar,
|
||
width: 51.sp,
|
||
height: 51.sp,
|
||
fit: BoxFit.cover,
|
||
),
|
||
),
|
||
SizedBox(
|
||
height: 4.sp,
|
||
),
|
||
Text(
|
||
info.nickName ?? info.user.nickname,
|
||
style: TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 14.sp),
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
)
|
||
],
|
||
),
|
||
),
|
||
);
|
||
},
|
||
itemCount: conList.length + lists.length > 5
|
||
? 5
|
||
: conList.isNotEmpty
|
||
? conList.length
|
||
: lists.length,
|
||
),
|
||
),
|
||
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!);
|
||
}
|
||
}
|
||
|
||
void loadFollowMeData() async {
|
||
List<V2TimUserFullInfo> stataionList = [];
|
||
if (conList.isEmpty) {
|
||
stataionList = await loadConverstationListData();
|
||
}
|
||
Map typeMap = {
|
||
'官方通知': 1,
|
||
'活动驿站': 2,
|
||
'会员中心': 3,
|
||
'资产中心': 4,
|
||
'乐园圈子': 5,
|
||
'互动通知': 6,
|
||
};
|
||
|
||
stataionList.forEach((element) {
|
||
if (!typeMap.containsKey(element.nickName ?? '')) {
|
||
conList.add(element);
|
||
}
|
||
});
|
||
|
||
if (conList.length < 5) {
|
||
var data = await DioManager.instance
|
||
.get(url: Api.fansList, params: {'page': 1, 'page_size': 6});
|
||
var bean = BaseResponse<UserList>.fromJson(
|
||
data, (data) => UserList.fromJson(data));
|
||
if (bean.isSuccess()) {
|
||
bean.data.lists.forEach((element) {
|
||
bool isContain = false;
|
||
conList.forEach((user) {
|
||
if (element.user.imId == user.userID!) {
|
||
isContain = true;
|
||
}
|
||
});
|
||
if (!isContain) {
|
||
lists.add(element);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
setState(() {});
|
||
}
|
||
}
|