|
|
|
@ -1,18 +1,20 @@
|
|
|
|
|
import 'dart:collection'; |
|
|
|
|
import 'dart:convert'; |
|
|
|
|
|
|
|
|
|
import 'package:dio/dio.dart'; |
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
|
|
|
|
import 'package:huixiang/generated/l10n.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/login_info.dart'; |
|
|
|
|
import 'package:huixiang/utils/flutter_utils.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/coupon.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart'; |
|
|
|
|
import 'package:huixiang/utils/font_weight.dart'; |
|
|
|
|
import 'package:huixiang/view_widget/receive_success.dart'; |
|
|
|
|
import 'package:huixiang/view_widget/round_button.dart'; |
|
|
|
|
import 'package:huixiang/view_widget/separator.dart'; |
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
|
|
|
|
|
|
class ActivityCoupons extends StatefulWidget { |
|
|
|
|
// final List<NewUserCouponList> newUserCouponList; |
|
|
|
|
// |
|
|
|
|
// ActivityCoupons(this.newUserCouponList); |
|
|
|
|
final String result; |
|
|
|
|
|
|
|
|
|
ActivityCoupons(this.result); |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
State<StatefulWidget> createState() { |
|
|
|
@ -21,16 +23,53 @@ class ActivityCoupons extends StatefulWidget {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class _ActivityCoupons extends State<ActivityCoupons> { |
|
|
|
|
var resultData; |
|
|
|
|
int pageNum = 1; |
|
|
|
|
List<Coupon> coupons = []; |
|
|
|
|
ApiService apiService; |
|
|
|
|
var receiveCou = new Queue(); |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
void initState() { |
|
|
|
|
super.initState(); |
|
|
|
|
resultData = jsonDecode(widget.result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
receiveCoupon() async { |
|
|
|
|
var id = receiveCou.removeFirst(); |
|
|
|
|
if (apiService == null) { |
|
|
|
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
|
|
|
apiService = ApiService( |
|
|
|
|
Dio(), |
|
|
|
|
context: context, |
|
|
|
|
token: value.getString("token"), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
BaseData baseData = await apiService.receiveCoupon(id).catchError((onError) {}); |
|
|
|
|
if (baseData != null && baseData.isSuccess) { |
|
|
|
|
if (receiveCou.length > 0) { |
|
|
|
|
receiveCoupon(); |
|
|
|
|
} else { |
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
SmartDialog.showToast("领取成功", alignment: Alignment.center); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
SmartDialog.showToast(baseData.msg, alignment: Alignment.center); |
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
return Container( |
|
|
|
|
margin: EdgeInsets.only(top:150.h), |
|
|
|
|
margin: EdgeInsets.only(top: 150.h), |
|
|
|
|
height: MediaQuery.of(context).size.height / 2, |
|
|
|
|
child: Column( |
|
|
|
|
children: [ |
|
|
|
|
Container( |
|
|
|
|
width: double.infinity, |
|
|
|
|
height:MediaQuery.of(context).size.height / 2, |
|
|
|
|
height: MediaQuery.of(context).size.height / 2, |
|
|
|
|
padding: EdgeInsets.only(top: 210.h), |
|
|
|
|
margin: EdgeInsets.only(top: 20.h, left: 20, right: 20), |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
@ -42,16 +81,18 @@ class _ActivityCoupons extends State<ActivityCoupons> {
|
|
|
|
|
child: Column( |
|
|
|
|
children: [ |
|
|
|
|
Expanded( |
|
|
|
|
child: reward(), |
|
|
|
|
child: couponsActivity(), |
|
|
|
|
), |
|
|
|
|
GestureDetector( |
|
|
|
|
onTap: () { |
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
SmartDialog.showToast("领取成功",alignment: Alignment.center); |
|
|
|
|
(resultData["list"] as List).forEach((element) { |
|
|
|
|
receiveCou..add(element["id"]); |
|
|
|
|
}); |
|
|
|
|
receiveCoupon(); |
|
|
|
|
}, |
|
|
|
|
child: Container( |
|
|
|
|
margin: EdgeInsets.only( |
|
|
|
|
left: 60.w, right: 60.w, top: 20.h, bottom:20.h), |
|
|
|
|
left: 60.w, right: 60.w, top: 20.h, bottom: 20.h), |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
gradient: new LinearGradient( |
|
|
|
|
begin: Alignment.centerLeft, |
|
|
|
@ -96,23 +137,25 @@ class _ActivityCoupons extends State<ActivityCoupons> {
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Widget reward() { |
|
|
|
|
Widget couponsActivity() { |
|
|
|
|
return ListView.builder( |
|
|
|
|
padding: EdgeInsets.zero, |
|
|
|
|
itemCount: 4, |
|
|
|
|
itemCount: (resultData == null || resultData["list"] == null) |
|
|
|
|
? 0 |
|
|
|
|
: (resultData["list"] as List).length, |
|
|
|
|
scrollDirection: Axis.vertical, |
|
|
|
|
shrinkWrap: true, |
|
|
|
|
physics: BouncingScrollPhysics(), |
|
|
|
|
itemBuilder: (context, position) { |
|
|
|
|
return GestureDetector( |
|
|
|
|
onTap: () {}, |
|
|
|
|
child: rewardItem(), |
|
|
|
|
child: couponsItem(resultData["list"][position]), |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Widget rewardItem() { |
|
|
|
|
Widget couponsItem(listData) { |
|
|
|
|
return Container( |
|
|
|
|
height: 69.h, |
|
|
|
|
width: double.infinity, |
|
|
|
@ -123,31 +166,27 @@ class _ActivityCoupons extends State<ActivityCoupons> {
|
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 60, vertical: 5), |
|
|
|
|
padding: EdgeInsets.only(left: 16.w, right: 25.w), |
|
|
|
|
padding: EdgeInsets.only(left: 16.w, right: 10.w), |
|
|
|
|
child: Row( |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
|
children: [ |
|
|
|
|
if (listData["type"] == 1) |
|
|
|
|
Text.rich( |
|
|
|
|
TextSpan( |
|
|
|
|
children: [ |
|
|
|
|
TextSpan( |
|
|
|
|
text: "¥", |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 25.sp, |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
fontWeight: MyFontWeight.semi_bold, |
|
|
|
|
color: Color(0xFFDE5F3B), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
TextSpan( |
|
|
|
|
// text: double.tryParse( |
|
|
|
|
// "${newUserCouponList.discountAmount}" ?? "0") |
|
|
|
|
// .toInt() |
|
|
|
|
// .toString() ?? |
|
|
|
|
// "", |
|
|
|
|
text: "10", |
|
|
|
|
text: listData["discount"] ?? "", |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 35.sp, |
|
|
|
|
fontSize: 20.sp, |
|
|
|
|
fontWeight: MyFontWeight.semi_bold, |
|
|
|
|
color: Color(0xFFDE5F3B), |
|
|
|
|
), |
|
|
|
@ -155,45 +194,59 @@ class _ActivityCoupons extends State<ActivityCoupons> {
|
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Expanded(child:Padding( |
|
|
|
|
padding: EdgeInsets.only(top: 4, bottom: 4,left:10), |
|
|
|
|
child: Column( |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
|
children: [ |
|
|
|
|
if (listData["type"] == 3) |
|
|
|
|
Text( |
|
|
|
|
"海峡姐妹茶吧", |
|
|
|
|
"兑换券", |
|
|
|
|
overflow: TextOverflow.ellipsis, |
|
|
|
|
maxLines: 2, |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
fontWeight: MyFontWeight.semi_bold, |
|
|
|
|
color: Color(0xFF181818), |
|
|
|
|
color: Color(0xFFDE5F3B), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Text( |
|
|
|
|
"10元代金劵一张", |
|
|
|
|
overflow: TextOverflow.ellipsis, |
|
|
|
|
maxLines: 2, |
|
|
|
|
if (listData["type"] == 2) |
|
|
|
|
Padding( |
|
|
|
|
padding: EdgeInsets.only(right: 20), |
|
|
|
|
child: Text.rich( |
|
|
|
|
TextSpan( |
|
|
|
|
children: [ |
|
|
|
|
TextSpan( |
|
|
|
|
text: (listData["percent"] / 10).toString() ?? "", |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 25.sp, |
|
|
|
|
fontWeight: MyFontWeight.semi_bold, |
|
|
|
|
color: Color(0xFFDE5F3B), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
TextSpan( |
|
|
|
|
text: "折", |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 12.sp, |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
color: Color(0xFFD3623D), |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
fontWeight: MyFontWeight.semi_bold, |
|
|
|
|
color: Color(0xFFDE5F3B), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
)), |
|
|
|
|
Expanded( |
|
|
|
|
child: Padding( |
|
|
|
|
padding: EdgeInsets.only(top: 4, bottom: 4, left: 10), |
|
|
|
|
child: Column( |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
|
children: [ |
|
|
|
|
Text( |
|
|
|
|
// "有效期至:${(newUserCouponList.useEndTime != null && newUserCouponList.useEndTime != "") |
|
|
|
|
// ? newUserCouponList.useEndTime.split(" ")[0] |
|
|
|
|
// : "$newUserCouponList.useEndTime"}", |
|
|
|
|
"有效期至:2021-07-30", |
|
|
|
|
listData["name"] ?? "", |
|
|
|
|
overflow: TextOverflow.ellipsis, |
|
|
|
|
maxLines: 2, |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 10.sp, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
color: Color(0xFF727272), |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
fontWeight: MyFontWeight.semi_bold, |
|
|
|
|
color: Color(0xFF181818), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
], |
|
|
|
|
))), |
|
|
|
|
], |
|
|
|
|