421 lines
14 KiB
Dart
421 lines
14 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:circle_app/main.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:circle_app/common/colors/app_color.dart';
|
|
import 'package:circle_app/components/func_widget.dart';
|
|
import 'package:circle_app/network/api.dart';
|
|
import 'package:circle_app/network/dio_manager.dart';
|
|
import 'package:circle_app/util/util.dart';
|
|
|
|
import '../../../common/Widgets/RechargeScreenDialog.dart';
|
|
import '../../../common/Widgets/base_tip_widget.dart';
|
|
|
|
class Gift extends StatefulWidget {
|
|
String accid;
|
|
String giftId;
|
|
Gift(this.accid, this.giftId, {super.key});
|
|
@override
|
|
_GiftState createState() => _GiftState();
|
|
}
|
|
|
|
class _GiftState extends State<Gift> {
|
|
List giftList = [];
|
|
|
|
String giftId = '';
|
|
|
|
String tipStr = '';
|
|
String balanceTipStr = '充值';
|
|
|
|
String incomeBalance = '';
|
|
|
|
int giftCount = 1;
|
|
|
|
int selectedIndex = -1;
|
|
|
|
bool isShowCount = false;
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
giftId = widget.giftId;
|
|
loadGiftData();
|
|
getAsset();
|
|
}
|
|
|
|
gelectThirdItem() async {
|
|
var data =
|
|
await DioManager.getInstance().get(url: Api.walletRechargeSelectItem);
|
|
if (data['code'] == 200) {
|
|
// "walletRechargeSelectItemBos" -> [_GrowableList]
|
|
List response = data['data']['priceConfs'];
|
|
|
|
incomeBalance = data['data']['balance'].toString();
|
|
// List<RechargeItem> walletRechargeSelectItemBos = [];
|
|
AssetsDataDataPriceConfs info =
|
|
AssetsDataDataPriceConfs.fromJson(response.last);
|
|
balanceTipStr = info.remark!.isNotEmpty
|
|
? '首冲最高赠送' + info.remark!.split('送').last + '>'
|
|
: '充值>';
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Stack(
|
|
children: [
|
|
Container(
|
|
color: Colors.transparent,
|
|
child: Column(
|
|
children: [
|
|
widget.accid!.isNotEmpty
|
|
? Container(
|
|
margin: EdgeInsets.only(top: 10.sp, bottom: 10.sp),
|
|
width: Get.width,
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
tipStr.isNotEmpty ? '礼物送出后,获得$tipStr小时的消息置顶' : '',
|
|
style: TextStyle(
|
|
color: AppColor.mainColor,
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.w500),
|
|
),
|
|
)
|
|
: Container(),
|
|
Expanded(
|
|
child: Container(
|
|
width: Get.width,
|
|
child: ListView.builder(
|
|
itemCount: giftList.length,
|
|
scrollDirection: Axis.horizontal,
|
|
itemBuilder: (context, index) {
|
|
return giftGridWidget(giftList[index]);
|
|
}),
|
|
)),
|
|
Container(
|
|
padding: EdgeInsets.only(left: 16.sp, right: 16.sp),
|
|
height: 48.sp,
|
|
width: Get.width,
|
|
child: Row(
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () {
|
|
showRechargeScreenDialog().then((value) {
|
|
getAsset();
|
|
});
|
|
},
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
margin: EdgeInsets.only(right: 4.sp),
|
|
child: Image.asset(
|
|
getMineImage('bi_icon1'),
|
|
width: 24.sp,
|
|
),
|
|
),
|
|
Text(
|
|
'${incomeBalance}',
|
|
style: TextStyle(
|
|
color: Color(0xFFF7FAFA),
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.w500),
|
|
),
|
|
SizedBox(
|
|
width: 16.sp,
|
|
),
|
|
Text(
|
|
balanceTipStr,
|
|
style: TextStyle(
|
|
color: AppColor.mainColor,
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.w500),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(child: Container()),
|
|
GestureDetector(
|
|
onTap: () {
|
|
isShowCount = !isShowCount;
|
|
setState(() {});
|
|
},
|
|
child: Container(
|
|
height: 27.sp,
|
|
child: Row(
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () {
|
|
if (giftId.isEmpty) {
|
|
showOKToast('请选择您想求送的礼物');
|
|
} else {
|
|
sendGetGiftData();
|
|
}
|
|
},
|
|
child: Container(
|
|
width: 56.sp,
|
|
height: 27.sp,
|
|
decoration: BoxDecoration(
|
|
gradient: AppColor.mainVerLinearGradient,
|
|
borderRadius:
|
|
BorderRadius.circular(13.5.sp)),
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
'求送',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.w500),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: 8,
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
if (giftId.isEmpty) {
|
|
showOKToast('请选择您想赠送的礼物');
|
|
} else {
|
|
sendGiftData();
|
|
}
|
|
},
|
|
child: Container(
|
|
width: 56.sp,
|
|
height: 27.sp,
|
|
decoration: BoxDecoration(
|
|
gradient: AppColor.mainVerLinearGradient,
|
|
borderRadius:
|
|
BorderRadius.circular(13.5.sp)),
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
'赠送',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.w500),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
isShowCount
|
|
? Positioned(bottom: 45.sp, right: 15.sp, child: giftCountWidget())
|
|
: Container()
|
|
],
|
|
);
|
|
}
|
|
|
|
void sendGetGiftData() async {
|
|
var info = giftList[0][selectedIndex];
|
|
sendGetGiftCustomMsg(widget.accid, jsonEncode(info), '求您送我${info['name']}');
|
|
}
|
|
|
|
void sendGiftData() async {
|
|
var result = await DioManager.instance.post(url: Api.sendGift, params: {
|
|
'accid': widget.accid,
|
|
'giftId': giftId,
|
|
'num': giftCount,
|
|
'toUserId': widget.accid!.split('_').last
|
|
});
|
|
if (result['code'] == 200) {
|
|
showOKToast('赠送成功');
|
|
getAsset();
|
|
} else if (result['code'] == 31201) {
|
|
showOKToast(result['msg']);
|
|
showRechargeScreenDialog().then((value) => getAsset());
|
|
}
|
|
}
|
|
|
|
void loadGiftData() async {
|
|
var result = await DioManager.instance.get(url: Api.giftList);
|
|
if (result['code'] == 200) {
|
|
List dataList = result['data'];
|
|
List giftItemData = [];
|
|
|
|
for (int i = 0; i < dataList.length; i++) {
|
|
var info = dataList[i];
|
|
if (info['id'] == giftId) {
|
|
selectedIndex = i;
|
|
}
|
|
giftItemData.add(dataList[i]);
|
|
if (i % 7 == 0 && i != 0) {
|
|
List temp = [];
|
|
temp.addAll(giftItemData);
|
|
giftList.add(temp);
|
|
giftItemData.clear();
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < giftList[0].length; i++) {
|
|
var info = giftList[0][i];
|
|
if (info['name'] == '浪漫告白') {
|
|
selectedIndex = i;
|
|
giftId = info['id'].toString();
|
|
}
|
|
}
|
|
|
|
setState(() {});
|
|
}
|
|
}
|
|
|
|
getAsset() async {
|
|
var jsonMap = await DioManager.getInstance().get(url: Api.userAsset);
|
|
|
|
if (jsonMap['code'] == 200) {
|
|
incomeBalance = jsonMap['data']['balance'].toString();
|
|
await gelectThirdItem();
|
|
setState(() {});
|
|
}
|
|
}
|
|
|
|
giftGridWidget(List info) {
|
|
return Container(
|
|
width: Get.width,
|
|
// color: Colors.red,
|
|
height: 255.sp,
|
|
padding: EdgeInsets.only(left: 16.sp, right: 16.sp),
|
|
child: GridView.builder(
|
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 4,
|
|
crossAxisSpacing: 0.0.sp,
|
|
mainAxisSpacing: 0.sp,
|
|
childAspectRatio: (Get.width - 32.sp) / 4 / 127.5.sp,
|
|
),
|
|
itemCount: info.length,
|
|
// Replace with the actual item count
|
|
shrinkWrap: true,
|
|
physics: NeverScrollableScrollPhysics(),
|
|
itemBuilder: (context, index) {
|
|
// Replace the placeholders with the actual item widgets
|
|
return giftItemWidget(info[index], index);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
giftItemWidget(Map info, int index) {
|
|
bool isSelected = giftId.contains(info['id'].toString());
|
|
double price = info['price'];
|
|
|
|
return GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: () {
|
|
selectedIndex = index;
|
|
giftId = info['id'].toString();
|
|
tipStr = info['topHours'] != null ? info['topHours'].toString() : '';
|
|
setState(() {});
|
|
},
|
|
child: Container(
|
|
height: 127.5.sp,
|
|
// color: Colors.red,
|
|
// decoration: BoxDecoration(
|
|
// image: DecorationImage(
|
|
// image: AssetImage(getMsgImage('gift_bg'),),
|
|
// )
|
|
// // color: isSelected ? Color(0xFF3E3D4C) : Colors.transparent,
|
|
// // borderRadius: BorderRadius.circular(4.sp),
|
|
// // border: Border.all(
|
|
// // color: isSelected ? AppColor.mainColor : Colors.transparent,
|
|
// // width: isSelected ? 1.sp : 0.0)
|
|
// ),
|
|
child: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
isSelected
|
|
? Image.asset(
|
|
getMsgImage('gift_bg'),
|
|
)
|
|
: Container(),
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Image.network(
|
|
info['icon'],
|
|
width: 70.sp,
|
|
height: 70.sp,
|
|
),
|
|
Text(info['name'],
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.w500)),
|
|
Text('${price.toInt()}小票',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.w500))
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
giftCountWidget() {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: Color(0xFF3E3D4C), borderRadius: BorderRadius.circular(8.sp)),
|
|
child: Column(
|
|
children: [
|
|
giftCountItemWidget(1314, '一生一世', () {}),
|
|
giftCountItemWidget(520, '我爱你', () {}),
|
|
giftCountItemWidget(299, '爱久久', () {}),
|
|
giftCountItemWidget(66, '六六大顺', () {}),
|
|
giftCountItemWidget(10, '十全十美', () {}),
|
|
giftCountItemWidget(1, '一心一意', () {}),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
giftCountItemWidget(int count, String desc, GestureTapCallback callback) {
|
|
return GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: () {
|
|
giftCount = count;
|
|
isShowCount = false;
|
|
setState(() {});
|
|
},
|
|
child: Container(
|
|
height: 30.sp,
|
|
width: 115.sp,
|
|
padding: EdgeInsets.only(right: 5.sp),
|
|
child: Row(
|
|
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(
|
|
child: Container(
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
'${count}',
|
|
style:
|
|
TextStyle(color: Color(0xFFE6E6E6), fontSize: 12.sp),
|
|
))),
|
|
Expanded(
|
|
child: Container(
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
desc,
|
|
style:
|
|
TextStyle(color: Color(0xFFE6E6E6), fontSize: 12.sp),
|
|
))),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|