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.
149 lines
4.3 KiB
149 lines
4.3 KiB
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 MineCardInvalidPage extends StatefulWidget { |
|
@override |
|
State<StatefulWidget> createState() { |
|
return _MineCardInvalidPage(); |
|
} |
|
} |
|
|
|
class _MineCardInvalidPage extends State<MineCardInvalidPage> { |
|
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 != null && 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( |
|
appBar: AppBar( |
|
title: Text( |
|
S.of(context).shixiaoyouhuiquan, |
|
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: SmartRefresher( |
|
enablePullDown: true, |
|
enablePullUp: true, |
|
header: ClassicHeader(), |
|
footer: CustomFooter( |
|
builder: (context, mode) { |
|
Widget body; |
|
if (mode == LoadStatus.idle) { |
|
body = Text("pull up load"); |
|
} else if (mode == LoadStatus.loading) { |
|
body = CupertinoActivityIndicator(); |
|
} else if (mode == LoadStatus.failed) { |
|
body = Text("Load Failed!Click retry!"); |
|
} else if (mode == LoadStatus.canLoading) { |
|
body = Text("release to load more"); |
|
} else { |
|
body = Text(S.of(context).meiyougengduoyouhuiquan); |
|
} |
|
return Container( |
|
height: 55.0, |
|
child: Center(child: body), |
|
); |
|
}, |
|
), |
|
controller: _refreshController, |
|
onRefresh: _onRefresh, |
|
onLoading: queryCard, |
|
child: ListView.builder( |
|
itemBuilder: (context, position) { |
|
return CouponWidget(coupons[position], null); |
|
}, |
|
itemCount: coupons.length, |
|
), |
|
), |
|
), |
|
); |
|
} |
|
}
|
|
|