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.
273 lines
8.9 KiB
273 lines
8.9 KiB
4 years ago
|
import 'package:dio/dio.dart';
|
||
|
import 'package:flutter/cupertino.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:fluttertoast/fluttertoast.dart';
|
||
|
import 'package:huixiang/generated/l10n.dart';
|
||
|
import 'package:huixiang/retrofit/data/base_data.dart';
|
||
|
import 'package:huixiang/retrofit/data/coupon.dart';
|
||
|
import 'package:huixiang/retrofit/data/page.dart';
|
||
|
import 'package:huixiang/retrofit/retrofit_api.dart';
|
||
|
import 'package:huixiang/view_widget/coupon_widget.dart';
|
||
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||
|
|
||
|
class CouponsPage extends StatefulWidget {
|
||
|
@override
|
||
|
State<StatefulWidget> createState() {
|
||
|
return _CouponsPage();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class _CouponsPage extends State<CouponsPage> {
|
||
|
RefreshController _refreshController;
|
||
|
|
||
|
ApiService apiService;
|
||
|
|
||
|
@override
|
||
|
void initState() {
|
||
|
super.initState();
|
||
|
|
||
|
SharedPreferences.getInstance().then((value) => {
|
||
|
apiService = ApiService(Dio(), token: value.getString('token')),
|
||
|
queryCard(),
|
||
|
});
|
||
|
|
||
|
_refreshController = RefreshController(initialRefresh: false);
|
||
|
}
|
||
|
|
||
|
int pageNum = 1;
|
||
|
List<Coupon> coupons = [];
|
||
|
|
||
|
void _onRefresh() async {
|
||
|
pageNum = 1;
|
||
|
queryCard();
|
||
|
}
|
||
|
|
||
|
queryCard() async {
|
||
|
BaseData baseData = await apiService.queryCard({
|
||
|
"centre": true,
|
||
|
"pageNum": pageNum,
|
||
|
"pageSize": 10,
|
||
|
"searchKey": "",
|
||
|
"state": 3
|
||
|
}).catchError((error) {
|
||
|
_refreshController.loadFailed();
|
||
|
_refreshController.refreshFailed();
|
||
|
});
|
||
|
if (baseData.isSuccess) {
|
||
|
PageInfo pageInfo = PageInfo.fromJson(baseData.data);
|
||
|
if (pageNum == 1) {
|
||
|
coupons.clear();
|
||
|
}
|
||
|
coupons.addAll(pageInfo.list.map((e) => Coupon.fromJson(e)));
|
||
|
setState(() {
|
||
|
_refreshController.refreshCompleted();
|
||
|
_refreshController.loadComplete();
|
||
|
if (pageInfo.pageNum == pageInfo.pages) {
|
||
|
_refreshController.loadNoData();
|
||
|
} else {
|
||
|
pageNum += 1;
|
||
|
}
|
||
|
});
|
||
|
} else {
|
||
|
_refreshController.loadFailed();
|
||
|
_refreshController.refreshFailed();
|
||
|
Fluttertoast.showToast(msg: baseData.msg);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Scaffold(
|
||
|
body: Container(
|
||
|
child: Row(
|
||
|
children: [
|
||
|
Container(
|
||
|
width: 68,
|
||
|
height: 26,
|
||
|
alignment: Alignment.center,
|
||
|
margin: EdgeInsets.only(left: 16, right: 12, top: 10, bottom: 14),
|
||
|
decoration:BoxDecoration(
|
||
|
borderRadius: BorderRadius.all(Radius.circular(2)),
|
||
|
color: Colors.white,
|
||
|
),
|
||
|
child:GestureDetector(
|
||
|
onTap: (){
|
||
|
|
||
|
},
|
||
|
child: Text(
|
||
|
S.of(context).keyongquan,
|
||
|
style:TextStyle(
|
||
|
fontSize: 14,
|
||
|
fontWeight:FontWeight.bold,
|
||
|
color: Colors.black,
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
Container(
|
||
|
width: 68,
|
||
|
height: 26,
|
||
|
alignment: Alignment.center,
|
||
|
margin: EdgeInsets.only(left: 16, top: 10, bottom: 14),
|
||
|
decoration:BoxDecoration(
|
||
|
borderRadius: BorderRadius.all(Radius.circular(2)),
|
||
|
color: Color(0xffE5E5E5),
|
||
|
),
|
||
|
child:
|
||
|
GestureDetector(
|
||
|
onTap: (){
|
||
|
Navigator.of(context).pushNamed('/router/mine_card_invalid');
|
||
|
},
|
||
|
child: Text(
|
||
|
S.of(context).shixiaoquan,
|
||
|
style:TextStyle(
|
||
|
fontSize: 14,
|
||
|
color: Color(0xff727272),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
Widget vipCardItem() {
|
||
|
return Container(
|
||
|
margin: EdgeInsets.fromLTRB(16, 8, 16, 8),
|
||
|
// margin: EdgeInsets.all(16),
|
||
|
child: Stack(
|
||
|
// alignment: Alignment.center,
|
||
|
children: [
|
||
|
Image.asset(
|
||
|
"assets/image/icon_vip_bj.png",
|
||
|
fit: BoxFit.contain, //填充剩余空间
|
||
|
height: 185,
|
||
|
),
|
||
|
Container(
|
||
|
padding: EdgeInsets.only(left: 16,right: 16),
|
||
|
child:Column(
|
||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
SizedBox(height: 16),
|
||
|
Row(
|
||
|
children: [
|
||
|
ClipOval(
|
||
|
child:Image.asset(
|
||
|
"assets/image/icon_vip_name.png",
|
||
|
),
|
||
|
clipBehavior: Clip.hardEdge,
|
||
|
),
|
||
|
SizedBox(
|
||
|
width: 12,
|
||
|
),
|
||
|
Expanded(
|
||
|
child: Container(
|
||
|
height: 54,
|
||
|
child: Column(
|
||
|
mainAxisAlignment:
|
||
|
MainAxisAlignment.spaceEvenly,
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
Row(
|
||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||
|
children: [
|
||
|
Text(
|
||
|
"百年川椒火锅店",
|
||
|
overflow: TextOverflow.ellipsis,
|
||
|
maxLines: 2,
|
||
|
style: TextStyle(
|
||
|
fontSize: 20,
|
||
|
color: Colors.white,
|
||
|
),
|
||
|
),
|
||
|
Image.asset(
|
||
|
"assets/image/icon_vip.png",
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
Text.rich(
|
||
|
TextSpan(children: [
|
||
|
TextSpan(
|
||
|
text: "会员卡",
|
||
|
style: TextStyle(
|
||
|
fontSize: 12,
|
||
|
color: Colors.white),
|
||
|
),
|
||
|
]),
|
||
|
textDirection: TextDirection.ltr,
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
flex: 1,
|
||
|
)
|
||
|
],
|
||
|
),
|
||
|
SizedBox(height: 50),
|
||
|
Row(
|
||
|
textDirection: TextDirection.rtl,
|
||
|
children: [
|
||
|
Image.asset(
|
||
|
"assets/image/icon_right.png",
|
||
|
),
|
||
|
Text.rich(
|
||
|
TextSpan(children: [
|
||
|
TextSpan(
|
||
|
text: "查看详情",
|
||
|
style: TextStyle(fontSize: 12, color: Colors.white),
|
||
|
),
|
||
|
]),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
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.white),
|
||
|
),
|
||
|
]),
|
||
|
),
|
||
|
),
|
||
|
Text.rich(
|
||
|
TextSpan(children: [
|
||
|
TextSpan(
|
||
|
text: "有效期限:",
|
||
|
style: TextStyle(fontSize: 12, color: Colors.white),
|
||
|
),
|
||
|
]),
|
||
|
),
|
||
|
Text.rich(
|
||
|
TextSpan(children: [
|
||
|
TextSpan(
|
||
|
text: "长期有效",
|
||
|
style: TextStyle(fontSize: 12, color: Colors.white),
|
||
|
),
|
||
|
]),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|