|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:fluttertoast/fluttertoast.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/view_widget/classic_header.dart';
|
|
|
|
import 'package:huixiang/view_widget/my_footer.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 baseData = await apiService.vipList()
|
|
|
|
.catchError((error) {
|
|
|
|
_refreshController.refreshFailed();
|
|
|
|
});
|
|
|
|
if (baseData != null && baseData.isSuccess) {
|
|
|
|
coupons.clear();
|
|
|
|
coupons.addAll(
|
|
|
|
(baseData.data as List<dynamic>).map((e) => VipCard.fromJson(e)));
|
|
|
|
setState(() {
|
|
|
|
_refreshController.refreshCompleted();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
_refreshController.refreshFailed();
|
|
|
|
Fluttertoast.showToast(msg: baseData.msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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: ListView.builder(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 8.h),
|
|
|
|
itemBuilder: (context, position) {
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pushNamed('/router/vip_details_page');
|
|
|
|
},
|
|
|
|
child: vipCardItem(coupons[position]),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
itemCount: coupons != null ? coupons.length : 0,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget vipCardItem(VipCard vipCard) {
|
|
|
|
return Container(
|
|
|
|
margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w, 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(
|
|
|
|
"assets/image/icon_vip_bj.png",
|
|
|
|
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: [
|
|
|
|
ClipOval(
|
|
|
|
child: Image.asset(
|
|
|
|
"assets/image/icon_vip_name.png",
|
|
|
|
),
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: 12.w,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
height: 54.h,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment:
|
|
|
|
MainAxisAlignment.spaceEvenly,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
vipCard.nickname,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
maxLines: 2,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.black,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Image.asset(
|
|
|
|
"assets/image/icon_vip.png",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Text.rich(
|
|
|
|
TextSpan(children: [
|
|
|
|
TextSpan(
|
|
|
|
text: "会员卡",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.black),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
flex: 1,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(height: 50),
|
|
|
|
Row(
|
|
|
|
textDirection: TextDirection.rtl,
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.chevron_right,
|
|
|
|
color: Colors.black,
|
|
|
|
size: 24,
|
|
|
|
),
|
|
|
|
Text.rich(
|
|
|
|
TextSpan(children: [
|
|
|
|
TextSpan(
|
|
|
|
text: "查看详情",
|
|
|
|
style: TextStyle(fontSize: 12, fontWeight: FontWeight
|
|
|
|
.bold, color: Colors.black),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
|
|
|
child: Text.rich(
|
|
|
|
TextSpan(children: [
|
|
|
|
TextSpan(
|
|
|
|
text: "No.202107021324199",
|
|
|
|
style: TextStyle(fontSize: 14, color: Colors.black),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text.rich(
|
|
|
|
TextSpan(children: [
|
|
|
|
TextSpan(
|
|
|
|
text: "有效期限:",
|
|
|
|
style: TextStyle(fontSize: 12, color: Colors.black),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
Text.rich(
|
|
|
|
TextSpan(children: [
|
|
|
|
TextSpan(
|
|
|
|
text: "长期有效",
|
|
|
|
style: TextStyle(fontSize: 12, color: Colors.black),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|