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.

119 lines
3.2 KiB

4 years ago
import 'package:dio/dio.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/data/base_data.dart';
import 'package:huixiang/data/coupon.dart';
import 'package:huixiang/data/page.dart';
4 years ago
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/shared_preference.dart';
4 years ago
import 'package:huixiang/view_widget/coupon_widget.dart';
4 years ago
import 'package:huixiang/view_widget/my_appbar.dart';
4 years ago
import 'package:huixiang/view_widget/my_footer.dart';
4 years ago
import 'package:pull_to_refresh/pull_to_refresh.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
class MineCardInvalidPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MineCardInvalidPage();
}
}
class _MineCardInvalidPage extends State<MineCardInvalidPage> {
late RefreshController _refreshController;
4 years ago
ApiService? apiService;
4 years ago
4 years ago
@override
void dispose() {
super.dispose();
_refreshController.dispose();
}
4 years ago
@override
void initState() {
super.initState();
4 years ago
apiService = ApiService(Dio(), context: context, token: SharedInstance.instance.token);
queryCard();
4 years ago
4 years ago
_refreshController = RefreshController(initialRefresh: false);
}
4 years ago
int pageNum = 1;
List<Coupon> coupons = [];
4 years ago
void _onRefresh() async {
4 years ago
pageNum = 1;
queryCard();
4 years ago
}
4 years ago
queryCard() async {
BaseData<PageInfo<Coupon>>? baseData = await apiService?.queryCard({
4 years ago
"centre": true,
"pageNum": pageNum,
"pageSize": 10,
"searchKey": "",
"state": 3
}).catchError((error) {
_refreshController.loadFailed();
_refreshController.refreshFailed();
return BaseData<PageInfo<Coupon>>()..isSuccess = false;
4 years ago
});
if (baseData?.isSuccess ?? false) {
if (baseData?.data?.list?.isNotEmpty ?? false) {
if (pageNum == 1) {
coupons.clear();
}
coupons.addAll(baseData!.data!.list!);
4 years ago
}
setState(() {
_refreshController.refreshCompleted();
_refreshController.loadComplete();
if (baseData?.data?.pageNum == baseData?.data?.pages) {
4 years ago
_refreshController.loadNoData();
} else {
pageNum += 1;
}
});
} else {
_refreshController.loadFailed();
_refreshController.refreshFailed();
}
4 years ago
}
4 years ago
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
4 years ago
appBar: MyAppBar(
title: S.of(context).shixiaoyouhuiquan,
titleColor: Colors.black,
titleSize: 18.sp,
background: Color(0xFFF7F7F7),
leadingColor: Colors.black,
4 years ago
),
body: Container(
child: SmartRefresher(
enablePullDown: true,
enablePullUp: true,
header: ClassicHeader(),
footer: CustomFooter(
builder: (context, mode) {
4 years ago
return MyFooter(mode);
4 years ago
},
),
controller: _refreshController,
onRefresh: _onRefresh,
4 years ago
onLoading: queryCard,
4 years ago
child: ListView.builder(
4 years ago
itemBuilder: (context, position) {
4 years ago
return CouponWidget(coupons[position], null);
4 years ago
},
4 years ago
itemCount: coupons.length,
4 years ago
),
),
),
);
}
}