You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

861 lines
29 KiB

import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/invitation_list.dart';
import 'package:huixiang/retrofit/data/page.dart';
import 'package:huixiang/retrofit/data/user_info.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/flutter_utils.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/view_widget/my_footer.dart';
import 'package:huixiang/view_widget/no_data_view.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sharesdk_plugin/sharesdk_defines.dart';
import 'package:sharesdk_plugin/sharesdk_interface.dart';
import 'package:sharesdk_plugin/sharesdk_map.dart';
class InviteFriends extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _InviteFriends();
}
}
class _InviteFriends extends State<InviteFriends> {
ApiService apiService;
final RefreshController refreshController = RefreshController();
final ScrollController scrollController = ScrollController();
List<InvitationList> invitationList = [];
UserInfo userInfo;
int pageNum = 1;
String phone = "";
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) {
if (value.getString('user') != null && value.getString('user') != "") {
phone = UserInfo.fromJson(jsonDecode(value.getString('user'))).inviteCode;
setState(() {});
}
queryUserInfo();
queryInviteMember();
});
}
///邀请记录
queryInviteMember() async {
if (apiService == null) {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(
Dio(),
context: context,
token: value.getString("token"),
);
}
BaseData<PageInfo<InvitationList>> baseData =
await apiService.inviteMemberList({
"searchKey": "",
"pageNum": 1,
"pageSize": 100,
}).catchError((error) {
refreshController.refreshFailed();
});
if (baseData != null && baseData.isSuccess) {
if (pageNum == 1) {
invitationList.clear();
}
invitationList.addAll(baseData.data.list);
setState(() {
refreshController.refreshCompleted();
});
} else {
refreshController.refreshFailed();
}
}
///查询用户信息
queryUserInfo() async {
if (apiService == null) {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(
Dio(),
context: context,
token: value.getString("token"),
);
}
BaseData<UserInfo> baseDate =
await apiService.queryInfo().catchError((onError) {
refreshController.refreshFailed();
});
if (baseDate != null && baseDate.isSuccess) {
setState(() {
userInfo = baseDate.data;
});
SharedPreferences.getInstance().then(
(value) => {
value.setString('user', jsonEncode(baseDate.data)),
},
);
refreshController.refreshCompleted();
} else {
refreshController.refreshFailed();
}
EasyLoading.dismiss();
}
_onRefresh(){
queryUserInfo();
queryInviteMember();
}
@override
Widget build(BuildContext context) {
return Stack(
children: [
Scaffold(
backgroundColor: Color(0xFFF9FAF7),
appBar: AppBar(
backgroundColor: Colors.white,
leading: GestureDetector(
child: Icon(
Icons.clear,
color: Colors.black,
),
onTap: () {
Navigator.of(context).pop();
}),
title: Text(
S.of(context).yaoqinghaoyou,
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 17.sp,
color: Color(0xFF000000),
),
),
centerTitle: true,
elevation: 0.0,
// actions: [
// GestureDetector(
// child: Container(
// margin: EdgeInsets.only(right: 14),
// padding:EdgeInsets.only(left:70,right: 20),
// child: Icon(
// Icons.more_horiz,
// color: Colors.black,
// ),
// ),
// onTap: () {
// // Navigator.of(context).pop();
// // share();
// })
// ],
),
body: SmartRefresher(
controller: refreshController,
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
onRefresh: () {
setState(() {
_onRefresh();
});
},
physics: BouncingScrollPhysics(),
scrollController: scrollController,
child: Container(
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
children: [
invite(),
activityRule(),
achievement(),
mineInvite(),
],
),
),
),
),
),
],
);
}
///邀请图
Widget invite(){
return Container(
width:double.infinity,
height: 370.h,
margin: EdgeInsets.only(bottom:20.h),
child:Column(
children: [
Image.asset(
"assets/image/invite_friends.webp",
height: 300.h,
width:double.infinity,
fit: BoxFit.fill,
),
SizedBox(height: 12.h,),
GestureDetector(
onTap: (){
widgetToUrl();
},
child: Container(
width: double.infinity,
height: 52.h,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(26),
color: Color(0xFF32A060),
),
margin: EdgeInsets.symmetric(horizontal:14.w),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/image/wx.webp",
height: 20,
width:20,
fit: BoxFit.fill,
),
SizedBox(width:4.w,),
Text(
"邀请微信好友",
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 16.sp,
color: Color(0xFFFFFFFF),
),
)
],
),
),
)
],
),
);
}
///活动规则
Widget activityRule(){
return Container(
width:double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
color: Color(0xFFFFFFFF),
),
margin: EdgeInsets.only(bottom:12.h,left:14.h,right: 14.h),
padding: EdgeInsets.all(6),
child:Column(
// mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage("assets/image/invite_bj.webp"),
),
),
height: 54.h,
width:double.infinity,
alignment: Alignment.center,
child: Text(
S.of(context).huodongguize,
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 16.sp,
color: Color(0xFF32A060),
),
)
),
SizedBox(height: 17.h,),
IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/image/invite_wx.webp",
width: 42.h,
height: 42.h,
fit: BoxFit.cover,
),
Container(
width:50.w,
child: Flex(
children: List.generate(8, (_) {
return SizedBox(
width: 3,
height: 1,
child: DecoratedBox(
decoration:
BoxDecoration(color: Color(0xFF32A060)),
),
);
}),
mainAxisAlignment: MainAxisAlignment.spaceBetween,
direction: Axis.horizontal,
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/image/invite_1.webp",
width: 24.h,
height: 24.h,
fit: BoxFit.cover,
),
Container(
width: 44.w,
child: Flex(
children: List.generate(0, (_) {
return SizedBox(
width: 3.w,
height: 1.h,
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.white),
),
);
}),
mainAxisAlignment: MainAxisAlignment.spaceBetween,
direction: Axis.horizontal,
),
),
],
),
SizedBox(height: 8.h),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width:50.w,
child:
Text(
"分享链接给好友",
style: TextStyle(
fontSize: 12.sp,
height: 1.3.h,
fontWeight: MyFontWeight.regular,
color: Color(0xFF181818),
),
),
),
Container(
width: 43.w,
child: Flex(
children: List.generate(0, (_) {
return SizedBox(
width: 3.w,
height: 1.h,
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.white),
),
);
}),
mainAxisAlignment: MainAxisAlignment.spaceBetween,
direction: Axis.horizontal,
),
),
],
),
],
)),
Expanded(child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/image/yq_zt.webp",
width: 42.h,
height: 42.h,
fit: BoxFit.cover,
),
Container(
width: 50.w,
child: Flex(
children: List.generate(8, (_) {
return SizedBox(
width: 3.w,
height: 1.w,
child: DecoratedBox(
decoration:
BoxDecoration(color: Color(0xFF32A060)),
),
);
}),
mainAxisAlignment: MainAxisAlignment.spaceBetween,
direction: Axis.horizontal,
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/image/invite_2.webp",
width: 24.h,
height: 24.h,
fit: BoxFit.cover,
),
Container(
width: 44.w,
child: Flex(
children: List.generate(0, (_) {
return SizedBox(
width: 3.w,
height: 1.h,
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.white),
),
);
}),
mainAxisAlignment: MainAxisAlignment.spaceBetween,
direction: Axis.horizontal,
),
),
],
),
SizedBox(height: 8.h),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width:50.w,
child:
Text(
"好友注册并获得10元优惠券",
style: TextStyle(
fontSize: 12.sp,
height: 1.3.h,
fontWeight: MyFontWeight.regular,
color: Color(0xFF181818),
),
),
),
Container(
width: 43.w,
child: Flex(
children: List.generate(0, (_) {
return SizedBox(
width: 3.w,
height: 1.h,
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.white),
),
);
}),
mainAxisAlignment: MainAxisAlignment.spaceBetween,
direction: Axis.horizontal,
),
),
],
),
],
)),
Expanded(child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/image/zt_m.webp",
width: 42.h,
height: 42.h,
fit: BoxFit.cover,
),
Container(
width: 50.w,
child: Flex(
children: List.generate(8, (_) {
return SizedBox(
width: 3.w,
height: 1.h,
child: DecoratedBox(
decoration:
BoxDecoration(color: Color(0xFF32A060)),
),
);
}),
mainAxisAlignment: MainAxisAlignment.spaceBetween,
direction: Axis.horizontal,
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/image/invite_3.webp",
width: 24.h,
height: 24.h,
fit: BoxFit.cover,
),
Container(
width: 44.w,
child: Flex(
children: List.generate(0, (_) {
return SizedBox(
width: 3.w,
height: 1.h,
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.white),
),
);
}),
mainAxisAlignment: MainAxisAlignment.spaceBetween,
direction: Axis.horizontal,
),
),
],
),
SizedBox(height: 8.h),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: 50.w,
child:
Text(
"好友完成首单",
style: TextStyle(
fontSize: 12.sp,
height: 1.3.h,
fontWeight: MyFontWeight.regular,
color: Color(0xFF181818),
),
),
),
Container(
width: 43.w,
child: Flex(
children: List.generate(0, (_) {
return SizedBox(
width: 3.w,
height: 1.h,
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.white),
),
);
}),
mainAxisAlignment: MainAxisAlignment.spaceBetween,
direction: Axis.horizontal,
),
),
],
),
],
)),
Column(
children: [
Image.asset(
"assets/image/invite_q.webp",
width: 42.h,
height: 42.h,
fit: BoxFit.cover,
),
Image.asset(
"assets/image/invite_4.webp",
width: 24.h,
height: 24.h,
fit: BoxFit.cover,
),
SizedBox(height: 8.h),
Container(
width: 50.w,
child:
Text(
"邀请达成获得奖励",
style: TextStyle(
fontSize: 12.sp,
height: 1.3.h,
fontWeight: MyFontWeight.regular,
color: Color(0xFF181818),
),
),
)
],
)
,
],
),
),
],
),
);
}
///我的成就
Widget achievement(){
return Container(
width:double.infinity,
height: 150.h,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
color: Color(0xFFFFFFFF),
),
margin: EdgeInsets.only(bottom:12.h,left:14.h,right: 14.h),
padding: EdgeInsets.only(top: 6.h,left: 6,right: 6,bottom: 16.h),
child:Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage("assets/image/invite_bj.webp"),
),
),
height: 54.h,
width:double.infinity,
alignment: Alignment.center,
child: Text(
S.of(context).wodechengjiu,
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 16.sp,
color: Color(0xFF32A060),
),
)
),
Row(
children: [
Expanded(child:Column(
children: [
Text(
(userInfo?.todayInviteNumber ?? 0).toString(),
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 25.sp,
color: Color(0xFF000000),
),
),
SizedBox(height: 5.h,),
Text(
"今日邀请",
style: TextStyle(
fontWeight: MyFontWeight.regular,
fontSize: 12.sp,
color: Color(0xFF808080),
),
)
],
)),
Expanded(child:Column(
children: [
Text(
(userInfo?.inviteNumber ?? 0).toString(),
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 25.sp,
color: Color(0xFF000000),
),
),
SizedBox(height: 5.h,),
Text(
"累积邀请",
style: TextStyle(
fontWeight: MyFontWeight.regular,
fontSize: 12.sp,
color: Color(0xFF808080),
),
)
],
))
],
),
],
),
);
}
///我的邀请
Widget mineInvite(){
return Container(
width:double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
color: Color(0xFFFFFFFF),
),
margin: EdgeInsets.only(bottom:12.h,left:14.h,right: 14.h),
padding: EdgeInsets.only(top: 6.h,left: 6,right: 6),
child:Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage("assets/image/invite_bj.webp"),
),
),
height: 54.h,
width:double.infinity,
alignment: Alignment.center,
child: Text(
S.of(context).wodeyaoqing,
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 16.sp,
color: Color(0xFF32A060),
),
)
),
SizedBox(height:12.h,),
Padding(padding:EdgeInsets.symmetric(horizontal: 6.w),
child:
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
S.of(context).shoujihao,
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize:14.sp,
color: Color(0xFF000000),
),
),
Text(
"注册时间",
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize:14.sp,
color: Color(0xFF000000),
),
),
],),),
SizedBox(height:12.h,),
(invitationList.length == null || invitationList.length == 0)
? NoDataView(
src: "assets/image/ding_dan.webp",
isShowBtn: false,
text:"还没有邀请记录哦~",
fontSize: 16.sp,
margin: EdgeInsets.only(top: 120.h),
):ListView.builder(
padding: EdgeInsets.zero,
itemCount:invitationList.length,
scrollDirection: Axis.vertical,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, position) {
return GestureDetector(
onTap: () {
},
child: mineInviteItem(invitationList[position]),
);
},
),
],
),
);
}
Widget mineInviteItem(InvitationList invitationList){
return Container(
child:Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
AppUtils.phoneEncode(invitationList?.phone ?? ""),
style: TextStyle(
color: Color(0xFF000000),
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
),
),
Text(
invitationList?.createTime ?? "",
style: TextStyle(
color: Color(0xFF000000),
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
),
),
],
),
Container(
width: double.infinity,
height: 1.h,
color: Color(0xFFF7F7F7),
margin: EdgeInsets.symmetric(vertical: 12.h),
),
],
),
);
}
GlobalKey globalKey = GlobalKey();
widgetToUrl() async {
SSDKMap params = SSDKMap()
..setGeneral(
"邀请好友",
"",
[
"",
],
"",
"",
buildShareUrl(),
"",
"",
"",
"",
SSDKContentTypes.webpage,
);
SharesdkPlugin.share(ShareSDKPlatforms.wechatSession, params,
(state, userData, contentEntity, error) {
print("share!$state");
});
}
String buildShareUrl() {
return "https://hx.lotus-wallet.com/invite.html?invite=${phone}";
}
}