Browse Source

优惠券页面ui网络异常显示更改;

dart3
wurong 5 months ago
parent
commit
12cd12b26c
  1. 371
      lib/mine/coupon_page.dart

371
lib/mine/coupon_page.dart

@ -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,
@ -116,104 +118,99 @@ class _CouponPage extends State<CouponPage> {
children: [ children: [
Expanded( Expanded(
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
setState(() { setState(() {
state = 1; state = 1;
_onRefresh(); _onRefresh();
}); });
}, },
child: Container( child: Container(
width: double.infinity, width: double.infinity,
alignment: Alignment.center, alignment: Alignment.center,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: new BorderRadius.only( borderRadius: new BorderRadius.only(
topLeft: Radius.circular(6), topLeft: Radius.circular(6),
bottomLeft: Radius.circular(6), bottomLeft: Radius.circular(6),
), ),
border: Border.all( border: Border.all(
color: Color(0xFF32A060), color: Color(0xFF32A060),
width: 1, width: 1,
),
color: state == 1 ? Color(0xFF32A060) : Color(
0xFFFFFFFF),
),
child: Text(
S
.of(context)
.keyongquan,
style: TextStyle(
fontWeight: MyFontWeight.medium,
fontSize: 15.sp,
color: state == 1 ? Color(0xFFFFFFFF) : Color(
0xFF32A060),
),
),
), ),
)), color: state == 1 ? Color(0xFF32A060) : Color(0xFFFFFFFF),
),
child: Text(
S.of(context).keyongquan,
style: TextStyle(
fontWeight: MyFontWeight.medium,
fontSize: 15.sp,
color:
state == 1 ? Color(0xFFFFFFFF) : Color(0xFF32A060),
),
),
),
)),
Expanded( Expanded(
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
setState(() { setState(() {
state = 2; state = 2;
_onRefresh(); _onRefresh();
}); });
}, },
child: Container( child: Container(
width: double.infinity, width: double.infinity,
alignment: Alignment.center, alignment: Alignment.center,
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border( border: Border(
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(
0xFFFFFFFF),
),
child: Text(
S.of(context).yishiyong,
style: TextStyle(
fontWeight: MyFontWeight.medium,
fontSize: 15.sp,
color: state ==2 ? Color(0xFFFFFFFF) : Color(
0xFF32A060),
),
),
), ),
)), color: state == 2 ? Color(0xFF32A060) : Color(0xFFFFFFFF),
),
child: Text(
S.of(context).yishiyong,
style: TextStyle(
fontWeight: MyFontWeight.medium,
fontSize: 15.sp,
color:
state == 2 ? Color(0xFFFFFFFF) : Color(0xFF32A060),
),
),
),
)),
Expanded( Expanded(
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
setState(() { setState(() {
state = 3; state = 3;
_onRefresh(); _onRefresh();
}); });
}, },
child: Container( child: Container(
width: double.infinity, width: double.infinity,
alignment: Alignment.center, alignment: Alignment.center,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: new BorderRadius.only( borderRadius: new BorderRadius.only(
topRight: Radius.circular(6), topRight: Radius.circular(6),
bottomRight: Radius.circular(6), bottomRight: Radius.circular(6),
), ),
border: Border.all( border: Border.all(
color: Color(0xFF32A060), color: Color(0xFF32A060),
width: 1, width: 1,
),
color: state == 3 ? Color(0xFF32A060) : Color(
0xFFFFFFFF),
),
child: Text(
S.of(context).shixiaoquan,
style: TextStyle(
fontWeight: MyFontWeight.medium,
fontSize: 15.sp,
color: state == 3 ? Color(0xFFFFFFFF) : Color(
0xFF32A060),
),
),
), ),
)) color: state == 3 ? Color(0xFF32A060) : Color(0xFFFFFFFF),
),
child: Text(
S.of(context).shixiaoquan,
style: TextStyle(
fontWeight: MyFontWeight.medium,
fontSize: 15.sp,
color:
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);
} }
} }
}, },
@ -274,7 +272,7 @@ class _CouponPage extends State<CouponPage> {
!coupons[position].isEx; !coupons[position].isEx;
}); });
}, },
(){ () {
setState(() { setState(() {
showCouponDetails(position); showCouponDetails(position);
}); });
@ -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();
@ -310,11 +312,11 @@ class _CouponPage extends State<CouponPage> {
///使 ///使
showStoreSelector(storeList) { showStoreSelector(storeList) {
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
builder: (context) { builder: (context) {
return SelectorStoreWidget(storeList); return SelectorStoreWidget(storeList);
}, },
); );
} }
@ -331,21 +333,24 @@ class _CouponPage extends State<CouponPage> {
///使 ///使
showCouponDetails(index) { showCouponDetails(index) {
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
builder: (context) { builder: (context) {
return CouponDetailsWidget(coupons[index]); return CouponDetailsWidget(coupons[index]);
}, },
); );
} }
Widget couponItemSm(){ Widget couponItemSm() {
return Container( return Container(
height:143.h, height: 143.h,
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,
@ -359,45 +364,48 @@ class _CouponPage extends State<CouponPage> {
) )
], ],
), ),
child:Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
Expanded(child:Column( Expanded(
crossAxisAlignment: CrossAxisAlignment.start, child: Column(
mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ mainAxisAlignment: MainAxisAlignment.start,
Shimmer.fromColors( children: [
baseColor: Color(0XFFD8D8D8), Shimmer.fromColors(
highlightColor: Color(0XFFD8D8D8), baseColor: Color(0XFFD8D8D8),
child: Container( highlightColor: Color(0XFFD8D8D8),
color: Color(0XFFD8D8D8), child: Container(
width:143.w, color: Color(0XFFD8D8D8),
height: 21.h, width: 143.w,
height: 21.h,
),
), ),
), SizedBox(
SizedBox(height: 6.h,), height: 6.h,
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width:150.w,
height:17.h,
), ),
), Shimmer.fromColors(
Spacer(), baseColor: Color(0XFFD8D8D8),
Shimmer.fromColors( highlightColor: Color(0XFFD8D8D8),
baseColor: Color(0XFFD8D8D8), child: Container(
highlightColor: Color(0XFFD8D8D8), color: Color(0XFFD8D8D8),
child: Container( width: 150.w,
color: Color(0XFFD8D8D8), height: 17.h,
width:48.w, ),
height: 17.h,
), ),
), Spacer(),
], Shimmer.fromColors(
), baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 48.w,
height: 17.h,
),
),
],
),
), ),
Column( Column(
children: [ children: [
@ -406,21 +414,25 @@ class _CouponPage extends State<CouponPage> {
highlightColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8),
child: Container( child: Container(
color: Color(0XFFD8D8D8), color: Color(0XFFD8D8D8),
width:50.w, width: 50.w,
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),
child: Container( child: Container(
color: Color(0XFFD8D8D8), color: Color(0XFFD8D8D8),
width:59.w, width: 59.w,
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),
@ -429,7 +441,7 @@ class _CouponPage extends State<CouponPage> {
color: Color(0XFFD8D8D8), color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
), ),
width:64.w, width: 64.w,
height: 19.h, height: 19.h,
), ),
) )
@ -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),
)),
)
],
),
);
}
} }

Loading…
Cancel
Save