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 '../generated/l10n.dart'; import '../retrofit/data/base_data.dart'; import '../retrofit/data/user_info.dart'; import '../retrofit/retrofit_api.dart'; import '../utils/flutter_utils.dart'; import '../utils/font_weight.dart'; import '../view_widget/my_appbar.dart'; class VipPage extends StatefulWidget { VipPage(Key key): super(key: key); @override State createState() { return _VipPageState(); } } class _VipPageState extends State with AutomaticKeepAliveClientMixin { final RefreshController _refreshController = RefreshController(); ApiService apiService; VipCardHome vipHome; UserInfo userInfo; @override void dispose() { super.dispose(); if (_refreshController != null) _refreshController.dispose(); } @override void initState() { super.initState(); // queryVipHome(); queryUserBalance(); } ///查询会员信息 queryUserBalance() async { try{ if (apiService == null) { SharedPreferences value = await SharedPreferences.getInstance(); apiService = ApiService( Dio(), context: context, token: value.getString("token"), showLoading: true ); } BaseData baseData = await apiService.queryInfo().catchError((onError) { _refreshController.refreshFailed(); _refreshController.loadFailed();}); if (baseData != null && baseData.isSuccess) { userInfo = baseData.data; if (mounted) setState(() {}); _refreshController.refreshCompleted(); _refreshController.loadComplete(); }else { SmartDialog.showToast(baseData.msg, alignment: Alignment.center); _refreshController.refreshFailed(); _refreshController.loadFailed(); } }finally{ setState((){}); } } ///Vip季卡,月卡,首页接口(暂不用) queryVipHome() async { try{ if (apiService == null) { SharedPreferences value = await SharedPreferences.getInstance(); apiService = ApiService( Dio(), context: context, token: value.getString("token"), showLoading: true ); } BaseData baseData = await apiService.vipCardIndex().catchError((onError) { SmartDialog.showToast(AppUtils.dioErrorTypeToString(onError.type), alignment: Alignment.center); _refreshController.loadFailed(); _refreshController.refreshFailed(); }); if (baseData != null && baseData.isSuccess) { vipHome = baseData.data; _refreshController.refreshCompleted(); _refreshController.loadComplete(); }else{ SmartDialog.showToast(baseData.msg ?? "", alignment: Alignment.center); _refreshController.loadFailed(); _refreshController.refreshFailed(); } }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: () { queryUserBalance(); }, child: SingleChildScrollView( child: Container( child:Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ VipTop(vipHome, // (){queryVipHome();} ), // if(vipHome !=null) // VipGoodsDiscount(vipHome), ExclusiveCoupon(userInfo), vipRule(), SizedBox(height: 24.h,) ], ), ), ), ), ), ); } ///会员卡规则说明 Widget vipRule(){ return Container( margin: EdgeInsets.only(left: 14.w, right: 14.w, bottom:40.h,top:8.h), width: double.infinity, padding: EdgeInsets.only(top:14.h, left:20.h, bottom:8.h, right:20.w), decoration: BoxDecoration( borderRadius: BorderRadius.circular(6.w), color: Colors.white, boxShadow: [ BoxShadow( color: Colors.black.withAlpha(12), offset: Offset(0, 3), blurRadius: 14, spreadRadius: 0, ) ], ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Image.asset( "assets/image/vip_title.webp", fit: BoxFit.fill, //填充剩余空间 height: 13.h, width: 27.w, ), SizedBox( width: 4.w, ), Text( "会员卡说明", style: TextStyle( color: Colors.black, fontSize: 15.sp, fontWeight: MyFontWeight.semi_bold, ), ), ], ), SizedBox(height: 12.h,), Padding(padding:EdgeInsets.symmetric(vertical: 12.h), child:Text( "1.仅限使用储值金额消费时享受VIP权益(使用优惠券及其他支付方式均不享受VIP权益);", style: TextStyle( color: Color(0xFF6A6A6A), fontSize: 13.sp, height: 1.5.h, fontWeight: MyFontWeight.regular, ), )), Padding(padding:EdgeInsets.symmetric(vertical:6.h), child:Text( "2.储值余额不足时不享受VIP权益;", style: TextStyle( color: Color(0xFF6A6A6A), fontSize: 13.sp, height: 1.5.h, fontWeight: MyFontWeight.regular, ), )), Padding(padding:EdgeInsets.symmetric(vertical: 12.h), child:Text( "3.2023年6月1日前储值余额不享受VIP价格;", style: TextStyle( color: Color(0xFF6A6A6A), fontSize: 13.sp, height: 1.5.h, fontWeight: MyFontWeight.regular, ), )), ], ),); } @override bool get wantKeepAlive => true; }