You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
303 lines
11 KiB
303 lines
11 KiB
import 'package:dio/dio.dart'; |
|
import 'package:flutter/cupertino.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
import 'package:huixiang/retrofit/data/vip_card.dart'; |
|
import 'package:huixiang/retrofit/retrofit_api.dart'; |
|
import 'package:huixiang/utils/font_weight.dart'; |
|
import 'package:huixiang/view_widget/classic_header.dart'; |
|
import 'package:huixiang/view_widget/custom_image.dart'; |
|
import 'package:huixiang/view_widget/my_footer.dart'; |
|
import 'package:huixiang/view_widget/no_data_view.dart'; |
|
import 'package:pull_to_refresh/pull_to_refresh.dart'; |
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
class VipCardPage extends StatefulWidget { |
|
@override |
|
State<StatefulWidget> createState() { |
|
return _VipCardPage(); |
|
} |
|
} |
|
|
|
class _VipCardPage extends State<VipCardPage> { |
|
RefreshController _refreshController; |
|
|
|
ApiService apiService; |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
_refreshController = RefreshController(); |
|
|
|
SharedPreferences.getInstance().then((value) { |
|
apiService = |
|
ApiService(Dio(), context: context, token: value.getString("token")); |
|
queryVipCard(); |
|
}); |
|
} |
|
|
|
List<VipCard> coupons = []; |
|
|
|
queryVipCard() async { |
|
BaseData<List<VipCard>> baseData = |
|
await apiService.vipList({}).catchError((error) { |
|
_refreshController.refreshFailed(); |
|
}); |
|
if (baseData != null && baseData.isSuccess) { |
|
coupons.clear(); |
|
coupons.addAll(baseData.data); |
|
setState(() { |
|
_refreshController.refreshCompleted(); |
|
}); |
|
} else { |
|
_refreshController.refreshFailed(); |
|
} |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Scaffold( |
|
body: Container( |
|
child: SmartRefresher( |
|
enablePullDown: true, |
|
enablePullUp: false, |
|
header: MyHeader(), |
|
footer: CustomFooter( |
|
builder: (context, mode) { |
|
return MyFooter(mode); |
|
}, |
|
), |
|
controller: _refreshController, |
|
onRefresh: queryVipCard, |
|
physics: BouncingScrollPhysics(), |
|
child: (coupons != null && coupons.length > 0) |
|
? ListView.builder( |
|
padding: EdgeInsets.symmetric(vertical: 8.h), |
|
itemBuilder: (context, position) { |
|
return GestureDetector( |
|
onTap: () { |
|
Navigator.of(context).pushNamed( |
|
'/router/vip_details_page', |
|
arguments: {"id": coupons[position].id}); |
|
}, |
|
child: vipCardItem(coupons[position]), |
|
); |
|
}, |
|
itemCount: coupons != null ? coupons.length : 0, |
|
) |
|
: NoDataView( |
|
isShowBtn: false, |
|
text: "还没有会员卡~", |
|
fontSize: 16.sp, |
|
margin: EdgeInsets.only(top: 120.h), |
|
), |
|
), |
|
), |
|
); |
|
} |
|
|
|
String assetsByName(String storeName) { |
|
if (storeName == null) return "assets/image/icon_vip_bj.png"; |
|
if (storeName.contains("百年川椒") || storeName.contains("百年川椒")) { |
|
return "assets/image/icon_vip_bj.png"; |
|
} else if (storeName.contains("海峡姐妹") || storeName.contains("海峽姐妹")) { |
|
return "assets/image/icon_milk_tea_bg.png"; |
|
} else if (storeName.contains("前进麦味") || storeName.contains("前進麥味")) { |
|
return "assets/image/icon_bread_bg.png"; |
|
} |
|
return "assets/image/icon_vip_bj.png"; |
|
} |
|
|
|
Widget vipCardItem(VipCard vipCard) { |
|
return Container( |
|
margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h), |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.circular(8.w), |
|
color: Colors.white, |
|
boxShadow: [ |
|
BoxShadow( |
|
color: Colors.black.withAlpha(12), |
|
offset: Offset(0, 3), |
|
blurRadius: 14, |
|
spreadRadius: 0, |
|
) |
|
], |
|
), |
|
child: Stack( |
|
children: [ |
|
Positioned( |
|
child: ClipRRect( |
|
borderRadius: BorderRadius.circular(8.w), |
|
child: Image.asset( |
|
assetsByName(vipCard.tenantName), |
|
fit: BoxFit.cover, //填充剩余空间 |
|
height: 170.h, |
|
), |
|
), |
|
top: 0, |
|
left: 0, |
|
right: 0, |
|
bottom: 0, |
|
), |
|
Container( |
|
padding: EdgeInsets.all(16.w), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Row( |
|
children: [ |
|
MImage( |
|
(vipCard?.storeList?.length ?? 0) > 0 |
|
? vipCard.storeList[0].logo |
|
: "", |
|
width: 54, |
|
height: 54, |
|
fit: BoxFit.cover, |
|
radius: BorderRadius.circular(4), |
|
errorSrc: "assets/image/default_1.png", |
|
fadeSrc: "assets/image/default_1.png", |
|
), |
|
SizedBox( |
|
width: 12.w, |
|
), |
|
Expanded( |
|
child: Container( |
|
height: 54.h, |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Expanded( |
|
child: Text( |
|
vipCard.tenantName ?? "", |
|
overflow: TextOverflow.ellipsis, |
|
maxLines: 1, |
|
style: TextStyle( |
|
fontSize: 20.sp, |
|
fontWeight: FontWeight.bold, |
|
color: Colors.black, |
|
), |
|
), |
|
flex: 1, |
|
), |
|
Image.asset( |
|
"assets/image/icon_vip.png", |
|
), |
|
], |
|
), |
|
Text.rich( |
|
TextSpan( |
|
children: [ |
|
TextSpan( |
|
text: S.of(context).huiyuanka, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.medium, |
|
color: Colors.black, |
|
), |
|
), |
|
], |
|
), |
|
textDirection: TextDirection.ltr, |
|
), |
|
], |
|
), |
|
), |
|
flex: 1, |
|
) |
|
], |
|
), |
|
SizedBox(height: 50.h), |
|
Row( |
|
textDirection: TextDirection.rtl, |
|
children: [ |
|
Icon( |
|
Icons.chevron_right, |
|
color: Colors.black, |
|
size: 24, |
|
), |
|
Text.rich( |
|
TextSpan( |
|
children: [ |
|
TextSpan( |
|
text: S.of(context).chakanxiangqing, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.semi_bold, |
|
color: Colors.black, |
|
), |
|
), |
|
], |
|
), |
|
), |
|
], |
|
), |
|
SizedBox( |
|
height: 10.h, |
|
), |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Expanded( |
|
flex: 1, |
|
child: Text.rich( |
|
TextSpan( |
|
children: [ |
|
TextSpan( |
|
text: "No.${vipCard.id}", |
|
style: TextStyle( |
|
fontSize: 14.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Colors.black, |
|
), |
|
), |
|
], |
|
), |
|
), |
|
), |
|
Text.rich( |
|
TextSpan( |
|
children: [ |
|
TextSpan( |
|
text: S.of(context).youxiaoqixian, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0Xff353535), |
|
), |
|
), |
|
], |
|
), |
|
), |
|
Text.rich( |
|
TextSpan( |
|
children: [ |
|
TextSpan( |
|
text: S.of(context).changqiyouxiao, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0Xff353535), |
|
), |
|
), |
|
], |
|
), |
|
), |
|
], |
|
), |
|
], |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
}
|
|
|