|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/vip_card_home.dart';
|
|
|
|
import 'package:huixiang/view_widget/classic_header.dart';
|
|
|
|
import 'package:huixiang/vip/vip_view/exclusive_coupon.dart';
|
|
|
|
import 'package:huixiang/vip/vip_view/vip_goods_discount.dart';
|
|
|
|
import 'package:huixiang/vip/vip_view/vip_top.dart';
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
import '../retrofit/data/base_data.dart';
|
|
|
|
import '../retrofit/retrofit_api.dart';
|
|
|
|
import '../view_widget/my_appbar.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class VipPage extends StatefulWidget {
|
|
|
|
|
|
|
|
VipPage(Key key): super(key: key);
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _VipPageState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _VipPageState extends State<VipPage> with AutomaticKeepAliveClientMixin {
|
|
|
|
final RefreshController _refreshController = RefreshController();
|
|
|
|
ApiService apiService;
|
|
|
|
VipCardHome vipHome;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
if (_refreshController != null) _refreshController.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
queryVipHome();
|
|
|
|
}
|
|
|
|
|
|
|
|
queryVipHome() async {
|
|
|
|
try{
|
|
|
|
if (apiService == null) {
|
|
|
|
SharedPreferences value = await SharedPreferences.getInstance();
|
|
|
|
apiService = ApiService(
|
|
|
|
Dio(),
|
|
|
|
context: context,
|
|
|
|
token: value.getString("token"),
|
|
|
|
showLoading: true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
BaseData<VipCardHome> baseData =
|
|
|
|
await apiService.vipCardIndex().catchError((onError) {
|
|
|
|
_refreshController.refreshFailed();});
|
|
|
|
if (baseData != null && baseData.isSuccess) {
|
|
|
|
vipHome = baseData.data;
|
|
|
|
_refreshController.refreshCompleted();
|
|
|
|
}else{
|
|
|
|
_refreshController.refreshFailed();
|
|
|
|
SmartDialog.showToast(baseData.msg ?? "", alignment: Alignment.center);
|
|
|
|
}
|
|
|
|
}finally{
|
|
|
|
setState((){});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
super.build(context);
|
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: Color(0xFFF9FAF7),
|
|
|
|
body: Container(
|
|
|
|
padding: EdgeInsets.only(bottom: 76.h),
|
|
|
|
child: SmartRefresher(
|
|
|
|
controller: _refreshController,
|
|
|
|
enablePullDown: true,
|
|
|
|
enablePullUp: false,
|
|
|
|
header: MyHeader(),
|
|
|
|
physics: BouncingScrollPhysics(),
|
|
|
|
onRefresh: () {
|
|
|
|
queryVipHome();
|
|
|
|
},
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Container(
|
|
|
|
child:Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
VipTop(vipHome,(){
|
|
|
|
queryVipHome();
|
|
|
|
}),
|
|
|
|
|
|
|
|
if(vipHome !=null)
|
|
|
|
VipGoodsDiscount(vipHome),
|
|
|
|
|
|
|
|
ExclusiveCoupon(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool get wantKeepAlive => true;
|
|
|
|
}
|