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.
 
 
 
 
 
 

160 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/mine/vip_card_page.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/classic_header.dart';
import 'package:huixiang/view_widget/coupon_widget.dart';
import 'package:huixiang/view_widget/item_title.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 'coupons_page.dart';
class MineCardPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MineCardPage();
}
}
class _MineCardPage extends State<MineCardPage>
with SingleTickerProviderStateMixin{
RefreshController _refreshController;
List<Widget> _pages;
@override
void didChangeDependencies() {
super.didChangeDependencies();
_pages = [
VipCardPage(),
CouponsPage()
];
}
ApiService apiService;
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) => {
apiService = ApiService(Dio(), context: context, token: value.getString('token')),
queryCard(),
});
_refreshController = RefreshController(initialRefresh: false);
}
int pageNum = 1;
List<Coupon> coupons = [];
queryCard() async {
BaseData baseData = await apiService.queryCard({
"centre": true,
"pageNum": pageNum,
"pageSize": 10,
"searchKey": "",
"state": 1
}).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);
}
}
void _onRefresh() async {
pageNum = 1;
queryCard();
}
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: Text(
S.of(context).kaquan,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
centerTitle: false,
backgroundColor: Colors.white,
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,
bottom: TabBar(
// isScrollable: true, //可滚动
indicatorColor: Color(0xff39B54A),
labelColor: Colors.black,
labelStyle: TextStyle(fontSize: 17, fontWeight: FontWeight.bold),
unselectedLabelStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.normal,
),
// controller: tabController,
//未选中文字颜色
unselectedLabelColor: Color(0xffA29E9E),
indicatorSize: TabBarIndicatorSize.label, //指示器与文字等宽
tabs: <Widget>[
Tab(text: "会员卡"),
Tab(text: "券包"),
],
),
),
body: TabBarView(
children: _pages,
),
),
);
}
}