import 'dart:convert'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/page.dart'; import 'package:huixiang/retrofit/data/user_bill.dart'; import 'package:huixiang/retrofit/data/user_info.dart'; import 'package:huixiang/retrofit/data/vip_card.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/classic_header.dart'; import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/my_footer.dart'; import 'package:huixiang/view_widget/no_data_view.dart'; import 'package:huixiang/view_widget/round_button.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:shared_preferences/shared_preferences.dart'; class MineShopPage extends StatefulWidget { @override State createState() { return _MineShopPage(); } } class _MineShopPage extends State { List coupons = []; ApiService apiService; int current = 1; RefreshController refreshController ; @override void initState() { super.initState(); refreshController = RefreshController(); SharedPreferences.getInstance().then((value) { apiService = ApiService(Dio(), context: context, token: value.getString("token")); queryVipCard(); }); } _onRefresh() { current = 1; queryVipCard(); } queryVipCard() async { BaseData> baseData = await apiService.vipList({}).catchError((error) { refreshController.refreshFailed(); }); if (baseData != null && baseData.isSuccess) { coupons.clear(); coupons.addAll(baseData.data); setState(() { refreshController.refreshCompleted(); }); } else { refreshController.refreshFailed(); } } @override Widget build(BuildContext context) { return Scaffold( appBar: MyAppBar( title: S.of(context).dianpuyue, titleColor: Colors.black, background: Colors.white, leadingColor: Colors.black, ), body: SmartRefresher( enablePullDown: true, enablePullUp: false, header: MyHeader(), footer: CustomFooter( builder: (context, mode) { return MyFooter(mode); }, ), controller: refreshController, onRefresh: queryVipCard, physics: BouncingScrollPhysics(), child: (coupons != null && coupons.length > 0) ? ListView.builder( padding: EdgeInsets.symmetric(vertical: 8.h), itemBuilder: (context, position) { return GestureDetector( onTap: () { Navigator.of(context).pushNamed( '/router/mine_shop_details', arguments: {"id": coupons[position].id}); }, child: shopItem(coupons[position]), ); }, itemCount: coupons != null ? coupons.length : 0, ) : NoDataView( src: "assets/image/icon_empty.webp", isShowBtn: false, text: "还没有会员卡~", fontSize: 16.sp, margin: EdgeInsets.only(top: 120.h), ), ), ); } int colorByName(String storeName) { if (storeName == null) return 0xFF32A060; if (storeName.contains("百年川椒") || storeName.contains("百年川椒")) { return 0xFFC30D23; } else if (storeName.contains("海峡姐妹") || storeName.contains("海峽姐妹")) { return 0xFFE4C796; } else if (storeName.contains("前进麦味") || storeName.contains("前進麥味")) { return 0xFF265782; } return 0xFF32A060; } Widget shopItem(VipCard vipCard) { return Container( width:double.infinity, // height:140.h, margin: EdgeInsets.only(bottom: 12.h,top: 14.h,left: 14.w,right: 14.w), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( decoration: BoxDecoration( borderRadius: new BorderRadius.only( topLeft: Radius.circular(6), topRight: Radius.circular(6), ), color: Color(colorByName(vipCard.tenantName)), ), padding: EdgeInsets.only(left: 12.w), height: 62.h, child: Row( children: [ MImage( (vipCard?.storeList?.length ?? 0) > 0 ? vipCard.storeList[0].logo : "", width: 38, height: 38, fit: BoxFit.cover, radius: BorderRadius.circular(100), errorSrc: "assets/image/default_1.webp", fadeSrc: "assets/image/default_1.webp", ), SizedBox(width: 6,), Text( vipCard.tenantName ?? "", style: TextStyle( color: Color(0xFFFFFFFF), fontSize: 15.sp, fontWeight: MyFontWeight.medium, ), ), ], ), ), Container( decoration: BoxDecoration( borderRadius: new BorderRadius.only( bottomRight: Radius.circular(6), topRight: Radius.circular(6), ), color: Colors.white, ), padding: EdgeInsets.all(12.h), child: Column( children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( "店铺余额(元)", style: TextStyle( color: Color(0xFF262626), fontSize: 12.sp, fontWeight: MyFontWeight.regular, ), ), Text( "No.${vipCard.id}", style: TextStyle( color: Color(0xFF262626), fontSize: 12.sp, fontWeight: MyFontWeight.regular, ), ), ], ), SizedBox(height:4.h,), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded(child: Text( "¥${vipCard != null ? vipCard.balance : ""}", style: TextStyle( color: Color(0xFF262626), fontSize:24.sp, fontWeight: MyFontWeight.bold, ), )), Text( S.of(context).chakanxiangqing, style: TextStyle( color: Color(0xFF353535), fontSize: 12.sp, fontWeight: MyFontWeight.regular, ), ), SizedBox(width: 2,), Icon( Icons.chevron_right, size: 24, color: Colors.black, ), ], ), ], ), ), ], ), ); } }