|
|
|
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/item_title.dart';
|
|
|
|
import 'package:huixiang/view_widget/new_coupon_widget.dart';
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
class RollCenterPage extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _RollCenterPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _RollCenterPage extends State<RollCenterPage> {
|
|
|
|
RefreshController _refreshController;
|
|
|
|
|
|
|
|
ApiService apiService;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
SharedPreferences.getInstance().then((value) => {
|
|
|
|
apiService = ApiService(Dio(), context: context, token: value.getString('token')),
|
|
|
|
queryCoupon(),
|
|
|
|
});
|
|
|
|
_refreshController = RefreshController(initialRefresh: false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int pageNum = 1;
|
|
|
|
List<Coupon> coupons = [];
|
|
|
|
|
|
|
|
queryCoupon() async {
|
|
|
|
BaseData baseData = await apiService.queryCoupon({
|
|
|
|
"centre": true,
|
|
|
|
"pageNum": pageNum,
|
|
|
|
"pageSize": 10,
|
|
|
|
"searchKey": "",
|
|
|
|
"state": 1
|
|
|
|
});
|
|
|
|
if(baseData != null && baseData.isSuccess) {
|
|
|
|
PageInfo pageInfo = PageInfo.fromJson(baseData.data);
|
|
|
|
coupons.clear();
|
|
|
|
coupons.addAll(pageInfo.list.map((e) => Coupon.fromJson(e)).toList());
|
|
|
|
setState(() {});
|
|
|
|
} else {
|
|
|
|
Fluttertoast.showToast(msg: baseData.msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(
|
|
|
|
S.of(context).lingquanzhongxin,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
centerTitle: false,
|
|
|
|
backgroundColor: Color(0xFFF7F7F7),
|
|
|
|
elevation: 0,
|
|
|
|
leading: GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
margin: EdgeInsets.only(left: 10),
|
|
|
|
padding: EdgeInsets.all(6),
|
|
|
|
child: Icon(
|
|
|
|
Icons.arrow_back_ios,
|
|
|
|
color: Colors.black,
|
|
|
|
size: 24,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
titleSpacing: 2,
|
|
|
|
leadingWidth: 56,
|
|
|
|
),
|
|
|
|
body: Container(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
ItemTitle(
|
|
|
|
text: S.of(context).kelingqudeyouhuiquan,
|
|
|
|
imgPath: "assets/image/icon_card_coupon.png",
|
|
|
|
moreText: S.of(context).chakanwodekaquan,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pushNamed('/router/mine_card');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Expanded(child: ListView.builder(
|
|
|
|
itemBuilder: (context, position) {
|
|
|
|
return GestureDetector(
|
|
|
|
child: NewCouponWidget(coupons[position],(){
|
|
|
|
queryCoupon();
|
|
|
|
},(){
|
|
|
|
setState(() {
|
|
|
|
coupons[position].isEx = !coupons[position].isEx;
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
itemCount: coupons != null ? coupons.length : 0,
|
|
|
|
),)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|