circle_app/circle_app/lib/app/chat/widget/wish_dialog.dart
2023-12-04 11:40:07 +07:00

293 lines
10 KiB
Dart

import 'dart:convert';
import 'package:circle_app/common/colors/app_color.dart';
import 'package:circle_app/util/util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_pickers/pickers.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../../network/api.dart';
import '../../../network/dio_manager.dart';
import '../../circle/view.dart';
class WishDialog extends StatefulWidget {
String accId;
WishDialog({super.key, required this.accId});
@override
_WishDialogState createState() => new _WishDialogState();
}
class _WishDialogState extends State<WishDialog> {
// TODO: add state variables and methods
List giftList = [];
String giftId = '';
String withStr = '';
int selectedIndex = 1;
List<String> optionList = [
'分享一张本人照片',
'给你我的联系方式',
'来一场浪漫的约会',
'来一次真诚的告白',
'玩一个刺激的游戏',
'透露一个小秘密',
'一起聊天半小时'
];
@override
void initState() {
// TODO: implement initState
super.initState();
loadGiftData();
}
void loadGiftData() async {
var result = await DioManager.instance.get(url: Api.giftList);
if (result['code'] == 200) {
giftList = result['data'];
for (int i= 0; i< giftList.length; i++) {
var info = giftList[i];
if (info['name'] == '浪漫告白') {
selectedIndex = i ;
giftId = info['id'].toString();
}
}
setState(() {});
}
}
giftGridWidget() {
return Container(
width: Get.width,
height: 102.sp,
padding:
EdgeInsets.only(left: 10.sp, right: 10.sp, top: 10.sp, bottom: 10.sp),
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: giftList.length,
itemBuilder: (context, index) {
// Replace the placeholders with the actual item widgets
return giftItemWidget(giftList[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: 78.sp,
width: 78.sp,
child: Stack(
fit: StackFit.expand,
children: [
isSelected ? Image.asset(getMsgImage('gift_bg')) : Container(),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.network(
info['icon'],
width: 65.sp,
height: 65.sp,
),
],
)
],
),
),
);
}
@override
Widget build(BuildContext context) {
// TODO: add widget build method
return Scaffold(
backgroundColor: Colors.transparent,
body: Column(
children: [
Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Get.back();
},
child: Container())),
SafeArea(
child: Container(
padding: EdgeInsets.only(left: 15.sp, right: 15.sp),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(10.sp),
bottomRight: Radius.circular(10.sp)),
color: Color(0xFF423055),
),
child: Column(
children: [
Container(
margin: EdgeInsets.only(top: 8.sp, bottom: 15.sp),
width: 30.sp,
height: 3.sp,
decoration: BoxDecoration(
color: Color(0x33FFFFFF),
borderRadius: BorderRadius.circular(1.5.sp)),
),
Text(
'对方满足你的愿望后要尽快兑现承诺哈,感恩是你们建立稳定关系的保障哦~',
style: TextStyle(color: Colors.white, fontSize: 15.sp),
),
Container(
height: 102.sp,
margin: EdgeInsets.only(top: 12.sp),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.sp),
gradient: LinearGradient(
colors: [Color(0xFF132B40), Color(0xFF251240)])),
child: giftGridWidget(),
),
GestureDetector(
onTap: () {
showOptionPiker(withStr);
},
// behavior: HitTestBehavior.opaque,
child: Container(
height: 30.sp,
padding: EdgeInsets.only(left: 10.sp, right: 10.sp),
margin: EdgeInsets.only(top: 12.sp),
decoration: BoxDecoration(
color: Color(0x1AFFFFFF),
borderRadius: BorderRadius.circular(15.sp)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'选择感恩方式',
style: TextStyle(
color: Color(0xB3FFFFFF), fontSize: 15.sp),
),
Row(
children: [
Text(
withStr.isNotEmpty ? withStr : '请选择',
style: TextStyle(
color: withStr.isNotEmpty
? AppColor.mainColor
: Colors.white,
fontSize: 15.sp),
),
Image.asset(
getHomeImage('icon_in'),
width: 24.sp,
)
],
),
],
),
)),
Container(
margin: EdgeInsets.only(top: 12.sp, bottom: 15.sp),
padding: EdgeInsets.only(left: 30.sp, right: 30.sp),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
onTap: () {
if (selectedIndex < 0) {
showOKToast('请选择一个礼物');
return;
}
var info = giftList[selectedIndex];
sendInventWishCustomMsg(
widget.accId, jsonEncode(info), '邀请你许个愿');
},
child: Container(
height: 42.sp,
width: 136.sp,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(21.sp),
gradient: AppColor.mainVerLinearGradient,
),
alignment: Alignment.center,
child: Text(
'邀请对方许愿',
style: TextStyle(
color: Colors.white,
fontSize: 16.sp,
fontWeight: FontWeight.w600),
),
),
),
GestureDetector(
onTap: () {
if (selectedIndex < 0) {
showOKToast('请选择一个礼物');
return;
} else if (withStr.isEmpty) {
showOKToast('请选择感恩方式');
return;
}
var info = giftList[selectedIndex];
info['option'] = withStr;
sendGetWishCustomMsg(widget.accId, jsonEncode(info),
'许愿:想要${info['name']}');
},
child: Container(
height: 42.sp,
width: 136.sp,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(21.sp),
gradient: const LinearGradient(
colors: [
Color(0xFF06F9FA),
Color(0xFF7660FF),
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
),
child: Text(
'立即许愿',
style: TextStyle(
color: Colors.white,
fontSize: 16.sp,
fontWeight: FontWeight.w600),
),
),
),
],
),
)
],
),
),
)
],
),
);
}
showOptionPiker(String text) {
Pickers.showSinglePicker(context,
pickerStyle: DefaultPickerStyle.dark(),
data: optionList,
selectData: text.isNotEmpty ? text : optionList[2],
onConfirm: (p, position) {
withStr = p;
setState(() {});
});
}
}