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:flutter/material.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:shimmer/shimmer.dart';
import '../utils/flutter_utils.dart';
class CouponPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
@ -31,6 +32,7 @@ class _CouponPage extends State<CouponPage> {
ApiService? apiService;
late RefreshController _refreshController;
int networkStatus = 0;
String networkError = "";
@override
void dispose() {
@ -67,7 +69,9 @@ class _CouponPage extends State<CouponPage> {
"searchKey": "",
"state": state
}).catchError((error) {
networkError = AppUtils.dioErrorTypeToString(error.type);
networkStatus = -1;
setState(() {});
_refreshController.loadFailed();
_refreshController.refreshFailed();
});
@ -98,9 +102,7 @@ class _CouponPage extends State<CouponPage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppBar(
title: S
.of(context)
.youhuiquan,
title: S.of(context).youhuiquan,
titleColor: Colors.black,
background: Color(0xFFFFFFFF),
leadingColor: Colors.black,
@ -116,104 +118,99 @@ class _CouponPage extends State<CouponPage> {
children: [
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
state = 1;
_onRefresh();
});
},
child: Container(
width: double.infinity,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: new BorderRadius.only(
topLeft: Radius.circular(6),
bottomLeft: Radius.circular(6),
),
border: Border.all(
color: Color(0xFF32A060),
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),
),
),
onTap: () {
setState(() {
state = 1;
_onRefresh();
});
},
child: Container(
width: double.infinity,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: new BorderRadius.only(
topLeft: Radius.circular(6),
bottomLeft: Radius.circular(6),
),
border: Border.all(
color: Color(0xFF32A060),
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),
),
),
),
)),
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
state = 2;
_onRefresh();
});
},
child: Container(
width: double.infinity,
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border(
top: 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),
),
),
onTap: () {
setState(() {
state = 2;
_onRefresh();
});
},
child: Container(
width: double.infinity,
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border(
top: 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),
),
),
),
)),
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
state = 3;
_onRefresh();
});
},
child: Container(
width: double.infinity,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: new BorderRadius.only(
topRight: Radius.circular(6),
bottomRight: Radius.circular(6),
),
border: Border.all(
color: Color(0xFF32A060),
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),
),
),
onTap: () {
setState(() {
state = 3;
_onRefresh();
});
},
child: Container(
width: double.infinity,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: new BorderRadius.only(
topRight: Radius.circular(6),
bottomRight: Radius.circular(6),
),
border: Border.all(
color: Color(0xFF32A060),
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),
),
),
),
))
],
),
),
@ -231,7 +228,8 @@ class _CouponPage extends State<CouponPage> {
),
onRefresh: _onRefresh,
onLoading: queryCard,
child: networkStatus == 0 ? ListView.builder(
child: networkStatus == -1?noNetwork():(networkStatus == 0
? ListView.builder(
itemCount: 10,
physics: BouncingScrollPhysics(),
shrinkWrap: true,
@ -241,7 +239,8 @@ class _CouponPage extends State<CouponPage> {
child: couponItemSm(),
);
},
):((coupons.length > 0)
)
: ((coupons.length > 0)
? ListView.builder(
itemBuilder: (context, position) {
return GestureDetector(
@ -264,7 +263,6 @@ class _CouponPage extends State<CouponPage> {
} else {
showStoreSelector(
coupons[position].storeList);
}
}
},
@ -274,7 +272,7 @@ class _CouponPage extends State<CouponPage> {
!coupons[position].isEx;
});
},
(){
() {
setState(() {
showCouponDetails(position);
});
@ -283,15 +281,18 @@ class _CouponPage extends State<CouponPage> {
),
);
},
itemCount: coupons != null ? coupons.length : 0,
itemCount:coupons.length??0,
)
: NoDataView(
src: "assets/image/ka.webp",
isShowBtn: false,
text: state == 1 ? "目前暂无优惠券,请到领劵中心领取哦~" :(state == 2 ? "目前暂无已使用的优惠券哦~" :"目前暂无失效的优惠券哦~"),
text: state == 1
? "目前暂无优惠券,请到领劵中心领取哦~"
: (state == 2 ? "目前暂无已使用的优惠券哦~" : "目前暂无失效的优惠券哦~"),
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 {
BaseData? baseData = await apiService?.receiveCoupon(couponId).catchError((onError) {});
BaseData? baseData =
await apiService?.receiveCoupon(couponId).catchError((onError) {});
if (baseData?.isSuccess ?? false) {
_onRefresh();
showAlertDialog();
@ -310,11 +312,11 @@ class _CouponPage extends State<CouponPage> {
///使
showStoreSelector(storeList) {
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) {
return SelectorStoreWidget(storeList);
},
context: context,
backgroundColor: Colors.transparent,
builder: (context) {
return SelectorStoreWidget(storeList);
},
);
}
@ -331,21 +333,24 @@ class _CouponPage extends State<CouponPage> {
///使
showCouponDetails(index) {
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) {
return CouponDetailsWidget(coupons[index]);
},
context: context,
backgroundColor: Colors.transparent,
builder: (context) {
return CouponDetailsWidget(coupons[index]);
},
);
}
Widget couponItemSm(){
Widget couponItemSm() {
return Container(
height:143.h,
height: 143.h,
width: double.infinity,
margin: EdgeInsets.fromLTRB(14.w, 6.h, 14.w, 6.h),
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(
color: Colors.white,
@ -359,45 +364,48 @@ class _CouponPage extends State<CouponPage> {
)
],
),
child:Row(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(child:Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width:143.w,
height: 21.h,
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 143.w,
height: 21.h,
),
),
),
SizedBox(height: 6.h,),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width:150.w,
height:17.h,
SizedBox(
height: 6.h,
),
),
Spacer(),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width:48.w,
height: 17.h,
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 150.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(
children: [
@ -406,21 +414,25 @@ class _CouponPage extends State<CouponPage> {
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width:50.w,
width: 50.w,
height: 50.h,
),
),
SizedBox(height: 10.h,),
SizedBox(
height: 10.h,
),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width:59.w,
height:17.h,
width: 59.w,
height: 17.h,
),
),
SizedBox(height:15.h,),
SizedBox(
height: 15.h,
),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
@ -429,7 +441,7 @@ class _CouponPage extends State<CouponPage> {
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(10),
),
width:64.w,
width: 64.w,
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