|
|
@ -1,4 +1,3 @@ |
|
|
|
|
|
|
|
|
|
|
|
import 'package:dio/dio.dart'; |
|
|
|
import 'package:dio/dio.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:huixiang/generated/l10n.dart'; |
|
|
|
import 'package:huixiang/generated/l10n.dart'; |
|
|
@ -20,6 +19,8 @@ import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
import 'package:shimmer/shimmer.dart'; |
|
|
|
import 'package:shimmer/shimmer.dart'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import '../utils/flutter_utils.dart'; |
|
|
|
|
|
|
|
|
|
|
|
class CouponPage extends StatefulWidget { |
|
|
|
class CouponPage extends StatefulWidget { |
|
|
|
@override |
|
|
|
@override |
|
|
|
State<StatefulWidget> createState() { |
|
|
|
State<StatefulWidget> createState() { |
|
|
@ -31,6 +32,7 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
ApiService? apiService; |
|
|
|
ApiService? apiService; |
|
|
|
late RefreshController _refreshController; |
|
|
|
late RefreshController _refreshController; |
|
|
|
int networkStatus = 0; |
|
|
|
int networkStatus = 0; |
|
|
|
|
|
|
|
String networkError = ""; |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
void dispose() { |
|
|
|
void dispose() { |
|
|
@ -67,7 +69,9 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
"searchKey": "", |
|
|
|
"searchKey": "", |
|
|
|
"state": state |
|
|
|
"state": state |
|
|
|
}).catchError((error) { |
|
|
|
}).catchError((error) { |
|
|
|
|
|
|
|
networkError = AppUtils.dioErrorTypeToString(error.type); |
|
|
|
networkStatus = -1; |
|
|
|
networkStatus = -1; |
|
|
|
|
|
|
|
setState(() {}); |
|
|
|
_refreshController.loadFailed(); |
|
|
|
_refreshController.loadFailed(); |
|
|
|
_refreshController.refreshFailed(); |
|
|
|
_refreshController.refreshFailed(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -98,9 +102,7 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
Widget build(BuildContext context) { |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return Scaffold( |
|
|
|
return Scaffold( |
|
|
|
appBar: MyAppBar( |
|
|
|
appBar: MyAppBar( |
|
|
|
title: S |
|
|
|
title: S.of(context).youhuiquan, |
|
|
|
.of(context) |
|
|
|
|
|
|
|
.youhuiquan, |
|
|
|
|
|
|
|
titleColor: Colors.black, |
|
|
|
titleColor: Colors.black, |
|
|
|
background: Color(0xFFFFFFFF), |
|
|
|
background: Color(0xFFFFFFFF), |
|
|
|
leadingColor: Colors.black, |
|
|
|
leadingColor: Colors.black, |
|
|
@ -134,18 +136,15 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
color: Color(0xFF32A060), |
|
|
|
color: Color(0xFF32A060), |
|
|
|
width: 1, |
|
|
|
width: 1, |
|
|
|
), |
|
|
|
), |
|
|
|
color: state == 1 ? Color(0xFF32A060) : Color( |
|
|
|
color: state == 1 ? Color(0xFF32A060) : Color(0xFFFFFFFF), |
|
|
|
0xFFFFFFFF), |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
child: Text( |
|
|
|
child: Text( |
|
|
|
S |
|
|
|
S.of(context).keyongquan, |
|
|
|
.of(context) |
|
|
|
|
|
|
|
.keyongquan, |
|
|
|
|
|
|
|
style: TextStyle( |
|
|
|
style: TextStyle( |
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
fontSize: 15.sp, |
|
|
|
fontSize: 15.sp, |
|
|
|
color: state == 1 ? Color(0xFFFFFFFF) : Color( |
|
|
|
color: |
|
|
|
0xFF32A060), |
|
|
|
state == 1 ? Color(0xFFFFFFFF) : Color(0xFF32A060), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
@ -166,16 +165,15 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
top: BorderSide(width: 1, color: Color(0xFF32A060)), |
|
|
|
top: BorderSide(width: 1, color: Color(0xFF32A060)), |
|
|
|
bottom: BorderSide(width: 1, color: Color(0xFF32A060)), |
|
|
|
bottom: BorderSide(width: 1, color: Color(0xFF32A060)), |
|
|
|
), |
|
|
|
), |
|
|
|
color: state == 2 ? Color(0xFF32A060) : Color( |
|
|
|
color: state == 2 ? Color(0xFF32A060) : Color(0xFFFFFFFF), |
|
|
|
0xFFFFFFFF), |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
child: Text( |
|
|
|
child: Text( |
|
|
|
S.of(context).yishiyong, |
|
|
|
S.of(context).yishiyong, |
|
|
|
style: TextStyle( |
|
|
|
style: TextStyle( |
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
fontSize: 15.sp, |
|
|
|
fontSize: 15.sp, |
|
|
|
color: state ==2 ? Color(0xFFFFFFFF) : Color( |
|
|
|
color: |
|
|
|
0xFF32A060), |
|
|
|
state == 2 ? Color(0xFFFFFFFF) : Color(0xFF32A060), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
@ -200,16 +198,15 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
color: Color(0xFF32A060), |
|
|
|
color: Color(0xFF32A060), |
|
|
|
width: 1, |
|
|
|
width: 1, |
|
|
|
), |
|
|
|
), |
|
|
|
color: state == 3 ? Color(0xFF32A060) : Color( |
|
|
|
color: state == 3 ? Color(0xFF32A060) : Color(0xFFFFFFFF), |
|
|
|
0xFFFFFFFF), |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
child: Text( |
|
|
|
child: Text( |
|
|
|
S.of(context).shixiaoquan, |
|
|
|
S.of(context).shixiaoquan, |
|
|
|
style: TextStyle( |
|
|
|
style: TextStyle( |
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
fontSize: 15.sp, |
|
|
|
fontSize: 15.sp, |
|
|
|
color: state == 3 ? Color(0xFFFFFFFF) : Color( |
|
|
|
color: |
|
|
|
0xFF32A060), |
|
|
|
state == 3 ? Color(0xFFFFFFFF) : Color(0xFF32A060), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
@ -231,7 +228,8 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
), |
|
|
|
), |
|
|
|
onRefresh: _onRefresh, |
|
|
|
onRefresh: _onRefresh, |
|
|
|
onLoading: queryCard, |
|
|
|
onLoading: queryCard, |
|
|
|
child: networkStatus == 0 ? ListView.builder( |
|
|
|
child: networkStatus == -1?noNetwork():(networkStatus == 0 |
|
|
|
|
|
|
|
? ListView.builder( |
|
|
|
itemCount: 10, |
|
|
|
itemCount: 10, |
|
|
|
physics: BouncingScrollPhysics(), |
|
|
|
physics: BouncingScrollPhysics(), |
|
|
|
shrinkWrap: true, |
|
|
|
shrinkWrap: true, |
|
|
@ -241,7 +239,8 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
child: couponItemSm(), |
|
|
|
child: couponItemSm(), |
|
|
|
); |
|
|
|
); |
|
|
|
}, |
|
|
|
}, |
|
|
|
):((coupons.length > 0) |
|
|
|
) |
|
|
|
|
|
|
|
: ((coupons.length > 0) |
|
|
|
? ListView.builder( |
|
|
|
? ListView.builder( |
|
|
|
itemBuilder: (context, position) { |
|
|
|
itemBuilder: (context, position) { |
|
|
|
return GestureDetector( |
|
|
|
return GestureDetector( |
|
|
@ -264,7 +263,6 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
showStoreSelector( |
|
|
|
showStoreSelector( |
|
|
|
coupons[position].storeList); |
|
|
|
coupons[position].storeList); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
@ -283,15 +281,18 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
); |
|
|
|
}, |
|
|
|
}, |
|
|
|
itemCount: coupons != null ? coupons.length : 0, |
|
|
|
itemCount:coupons.length??0, |
|
|
|
) |
|
|
|
) |
|
|
|
: NoDataView( |
|
|
|
: NoDataView( |
|
|
|
src: "assets/image/ka.webp", |
|
|
|
src: "assets/image/ka.webp", |
|
|
|
isShowBtn: false, |
|
|
|
isShowBtn: false, |
|
|
|
text: state == 1 ? "目前暂无优惠券,请到领劵中心领取哦~" :(state == 2 ? "目前暂无已使用的优惠券哦~" :"目前暂无失效的优惠券哦~"), |
|
|
|
text: state == 1 |
|
|
|
|
|
|
|
? "目前暂无优惠券,请到领劵中心领取哦~" |
|
|
|
|
|
|
|
: (state == 2 ? "目前暂无已使用的优惠券哦~" : "目前暂无失效的优惠券哦~"), |
|
|
|
fontSize: 16.sp, |
|
|
|
fontSize: 16.sp, |
|
|
|
margin: EdgeInsets.only(top: 120.h, left: 60, right: 60), |
|
|
|
margin: |
|
|
|
)), |
|
|
|
EdgeInsets.only(top: 120.h, left: 60, right: 60), |
|
|
|
|
|
|
|
))), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
], |
|
|
@ -300,7 +301,8 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
receiveCoupon(couponId) async { |
|
|
|
receiveCoupon(couponId) async { |
|
|
|
BaseData? baseData = await apiService?.receiveCoupon(couponId).catchError((onError) {}); |
|
|
|
BaseData? baseData = |
|
|
|
|
|
|
|
await apiService?.receiveCoupon(couponId).catchError((onError) {}); |
|
|
|
if (baseData?.isSuccess ?? false) { |
|
|
|
if (baseData?.isSuccess ?? false) { |
|
|
|
_onRefresh(); |
|
|
|
_onRefresh(); |
|
|
|
showAlertDialog(); |
|
|
|
showAlertDialog(); |
|
|
@ -345,7 +347,10 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
width: double.infinity, |
|
|
|
width: double.infinity, |
|
|
|
margin: EdgeInsets.fromLTRB(14.w, 6.h, 14.w, 6.h), |
|
|
|
margin: EdgeInsets.fromLTRB(14.w, 6.h, 14.w, 6.h), |
|
|
|
padding: EdgeInsets.only( |
|
|
|
padding: EdgeInsets.only( |
|
|
|
right:13.w,top: 12.h,bottom: 13.h,left: 18.w, |
|
|
|
right: 13.w, |
|
|
|
|
|
|
|
top: 12.h, |
|
|
|
|
|
|
|
bottom: 13.h, |
|
|
|
|
|
|
|
left: 18.w, |
|
|
|
), |
|
|
|
), |
|
|
|
decoration: BoxDecoration( |
|
|
|
decoration: BoxDecoration( |
|
|
|
color: Colors.white, |
|
|
|
color: Colors.white, |
|
|
@ -363,7 +368,8 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
mainAxisAlignment: MainAxisAlignment.start, |
|
|
|
mainAxisAlignment: MainAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
children: [ |
|
|
|
Expanded(child:Column( |
|
|
|
Expanded( |
|
|
|
|
|
|
|
child: Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
mainAxisAlignment: MainAxisAlignment.start, |
|
|
|
mainAxisAlignment: MainAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
children: [ |
|
|
@ -376,7 +382,9 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
height: 21.h, |
|
|
|
height: 21.h, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
SizedBox(height: 6.h,), |
|
|
|
SizedBox( |
|
|
|
|
|
|
|
height: 6.h, |
|
|
|
|
|
|
|
), |
|
|
|
Shimmer.fromColors( |
|
|
|
Shimmer.fromColors( |
|
|
|
baseColor: Color(0XFFD8D8D8), |
|
|
|
baseColor: Color(0XFFD8D8D8), |
|
|
|
highlightColor: Color(0XFFD8D8D8), |
|
|
|
highlightColor: Color(0XFFD8D8D8), |
|
|
@ -410,7 +418,9 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
height: 50.h, |
|
|
|
height: 50.h, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
SizedBox(height: 10.h,), |
|
|
|
SizedBox( |
|
|
|
|
|
|
|
height: 10.h, |
|
|
|
|
|
|
|
), |
|
|
|
Shimmer.fromColors( |
|
|
|
Shimmer.fromColors( |
|
|
|
baseColor: Color(0XFFD8D8D8), |
|
|
|
baseColor: Color(0XFFD8D8D8), |
|
|
|
highlightColor: Color(0XFFD8D8D8), |
|
|
|
highlightColor: Color(0XFFD8D8D8), |
|
|
@ -420,7 +430,9 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
height: 17.h, |
|
|
|
height: 17.h, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
SizedBox(height:15.h,), |
|
|
|
SizedBox( |
|
|
|
|
|
|
|
height: 15.h, |
|
|
|
|
|
|
|
), |
|
|
|
Shimmer.fromColors( |
|
|
|
Shimmer.fromColors( |
|
|
|
baseColor: Color(0XFFD8D8D8), |
|
|
|
baseColor: Color(0XFFD8D8D8), |
|
|
|
highlightColor: Color(0XFFD8D8D8), |
|
|
|
highlightColor: Color(0XFFD8D8D8), |
|
|
@ -440,4 +452,51 @@ class _CouponPage extends State<CouponPage> { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Widget noNetwork() { |
|
|
|
|
|
|
|
return Container( |
|
|
|
|
|
|
|
width: double.infinity, |
|
|
|
|
|
|
|
child: Column( |
|
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
|
|
|
|
children: [ |
|
|
|
|
|
|
|
Text( |
|
|
|
|
|
|
|
// "无法连接到网络", |
|
|
|
|
|
|
|
networkError.substring(0, networkError.indexOf(",")), |
|
|
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
|
|
|
color: Color(0xFF0D0D0D), |
|
|
|
|
|
|
|
fontWeight: MyFontWeight.bold), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
Padding( |
|
|
|
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 10.h), |
|
|
|
|
|
|
|
child: Text( |
|
|
|
|
|
|
|
"请检查网络设置或稍后重试", |
|
|
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
|
|
fontSize: 12.sp, |
|
|
|
|
|
|
|
color: Color(0xFF7A797F), |
|
|
|
|
|
|
|
fontWeight: MyFontWeight.regular), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
GestureDetector( |
|
|
|
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
|
|
|
onTap: () { |
|
|
|
|
|
|
|
_onRefresh(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
child: Container( |
|
|
|
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
|
|
|
color: Color(0xff32A060), |
|
|
|
|
|
|
|
borderRadius: BorderRadius.circular(15), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 3.h), |
|
|
|
|
|
|
|
child: Text( |
|
|
|
|
|
|
|
"重试", |
|
|
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
|
|
|
color: Colors.white, |
|
|
|
|
|
|
|
fontWeight: MyFontWeight.regular), |
|
|
|
|
|
|
|
)), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|