import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:yumi/app_localizations.dart'; import 'package:yumi/ui_kit/components/sc_compontent.dart'; import 'package:yumi/ui_kit/components/sc_tts.dart'; import 'package:yumi/app/constants/sc_global_config.dart'; import 'package:yumi/shared/tools/sc_loading_manager.dart'; import 'package:provider/provider.dart'; import 'package:yumi/ui_kit/components/sc_page_list.dart'; import 'package:yumi/shared/data_sources/sources/repositories/sc_store_repository_imp.dart'; import 'package:yumi/shared/business_logic/models/res/store_list_res.dart'; import 'package:yumi/services/auth/user_profile_manager.dart'; import 'package:yumi/ui_kit/widgets/store/props_store_headdress_detail_dialog.dart'; import 'package:yumi/ui_kit/widgets/store/store_bag_page_helpers.dart'; import '../../../shared/data_sources/models/enum/sc_currency_type.dart'; import '../../../shared/data_sources/models/enum/sc_props_type.dart'; ///头饰 class StoreHeaddressPage extends SCPageList { @override _StoreHeaddressPageState createState() => _StoreHeaddressPageState(); } class _StoreHeaddressPageState extends SCPageListState { //折扣 double disCount = 1; @override void initState() { super.initState(); enablePullUp = false; isGridView = true; gridViewCount = 3; padding = EdgeInsets.symmetric(horizontal: 6.w); backgroundColor = Colors.transparent; gridDelegate = SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: gridViewCount, mainAxisSpacing: 12.w, crossAxisSpacing: 12.w, childAspectRatio: 0.78, ); loadData(1); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.transparent, body: items.isEmpty && isLoading ? const SCStoreGridSkeleton() : buildList(context), ); } @override Widget buildItem(StoreListResBean res) { return GestureDetector( child: Container( decoration: BoxDecoration( color: res.isSelecte ? const Color(0xff18F2B1).withValues(alpha: 0.1) : SCGlobalConfig.businessLogicStrategy .getStoreItemBackgroundColor(), border: Border.all( color: res.isSelecte ? SCGlobalConfig.businessLogicStrategy .getStoreItemSelectedBorderColor() : SCGlobalConfig.businessLogicStrategy .getStoreItemUnselectedBorderColor(), width: 1.w, ), borderRadius: BorderRadius.all(Radius.circular(8.w)), ), child: Stack( children: [ Column( children: [ SizedBox(height: 10.w), netImage( url: res.res.propsResources?.cover ?? "", width: 55.w, height: 55.w, ), SizedBox(height: 3.w), buildStoreBagItemTitle( res.res.propsResources?.name ?? "", textColor: Colors.white, fontSize: 11.sp, ), SizedBox(height: 3.w), Row( mainAxisSize: MainAxisSize.min, children: [ SizedBox(width: 10.w), Expanded( child: Text.rich( textAlign: TextAlign.center, TextSpan( children: [ WidgetSpan( alignment: PlaceholderAlignment.middle, child: Image.asset( SCGlobalConfig.businessLogicStrategy .getStoreItemGoldIcon(), width: 22.w, ), ), TextSpan(text: " "), disCount < 1 ? TextSpan( text: "${res.res.propsPrices![0].amount}", style: TextStyle( fontSize: 12.sp, color: SCGlobalConfig.businessLogicStrategy .getStoreItemPriceTextColor(), fontWeight: FontWeight.w600, decoration: TextDecoration.lineThrough, ), ) : TextSpan(), disCount < 1 ? TextSpan(text: " ") : TextSpan(), TextSpan( text: "${((res.res.propsPrices![0].amount ?? 0) * disCount).toInt()}/${res.res.propsPrices![0].days} ${SCAppLocalizations.of(context)!.day}", style: TextStyle( fontSize: 12.sp, color: SCGlobalConfig.businessLogicStrategy .getStoreItemPriceTextColor(), fontWeight: FontWeight.w600, ), ), ], ), strutStyle: StrutStyle( height: 1.3, // 行高倍数 fontWeight: FontWeight.w500, forceStrutHeight: true, // 强制应用行高 ), ), ), SizedBox(width: 10.w), ], ), ], ), ], ), ), onTap: () { _selectItem(res); _showDetail(res.res); }, ); } ///加载数据 @override loadPage({ required int page, required Function(List) onSuccess, Function? onErr, }) async { try { List beans = []; var storeList = await SCStoreRepositoryImp().storeList( SCCurrencyType.GOLD.name, SCPropsType.AVATAR_FRAME.name, ); for (var value in storeList) { beans.add(StoreListResBean(value, false)); } onSuccess(beans); } catch (e) { if (onErr != null) { onErr(); } } } void _showDetail(StoreListRes res) { SmartDialog.show( tag: "showPropsDetail", alignment: Alignment.bottomCenter, animationType: SmartAnimationType.fade, builder: (_) { return PropsStoreHeaddressDetailDialog(res, disCount); }, ); } void _selectItem(StoreListResBean res) { for (var value in items) { value.isSelecte = false; } res.isSelecte = true; setState(() {}); } void _buy(StoreListResBean res) { if (res.res.propsPrices!.isEmpty) { return; } SCLoadingManager.show(); num days = res.res.propsPrices![0].days ?? 0; SCStoreRepositoryImp() .storePurchasing( res.res.id ?? "", SCPropsType.AVATAR_FRAME.name, SCCurrencyType.GOLD.name, "$days", ) .then((value) { SCTts.show(SCAppLocalizations.of(context)!.purchaseIsSuccessful); Provider.of( context, listen: false, ).updateBalance(value); SCLoadingManager.hide(); }) .catchError((e) { SCLoadingManager.hide(); }); } } class StoreListResBean { StoreListRes res; bool isSelecte = false; StoreListResBean(this.res, this.isSelecte); }