import 'dart:io'; import 'package:aslan/chatvibe_data/sources/local/user_manager.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:provider/provider.dart'; import '../../../app_localizations.dart'; import '../../../chatvibe_core/constants/at_global_config.dart'; import '../../../chatvibe_core/constants/at_screen.dart'; import '../../../chatvibe_core/routes/at_fluro_navigator.dart'; import '../../../chatvibe_core/utilities/at_loading_manager.dart'; import '../../../chatvibe_data/sources/repositories/user_repository_impl.dart'; import '../../../chatvibe_domain/models/res/at_web_pay_commodity_res.dart'; import '../../../chatvibe_domain/models/res/at_web_pay_user_profile_res.dart'; import '../../../chatvibe_managers/apple_payment_manager.dart'; import '../../../chatvibe_managers/google_payment_manager.dart'; import '../../../chatvibe_managers/user_profile_manager.dart'; import '../../../chatvibe_ui/components/appbar/chatvibe_appbar.dart'; import '../../../chatvibe_ui/components/at_compontent.dart'; import '../../../chatvibe_ui/components/at_debounce_widget.dart'; import '../../../chatvibe_ui/components/text/at_text.dart'; import '../../../chatvibe_ui/theme/chatvibe_theme.dart'; import '../../../main.dart'; import '../../index/main_route.dart'; import '../wallet_route.dart'; import 'at_pay_custom_price_item_page.dart'; import 'at_pay_google_apple_price_item_page.dart'; import 'contry/pay_select_country_page.dart'; class ATRechargePageV2 extends StatefulWidget { @override _ATRechargePageV2State createState() => _ATRechargePageV2State(); } class _ATRechargePageV2State extends State with RouteAware { bool _hasPersmission = false; CountryList? _selectedCountry; List _countryList = []; List _channels = []; List _commodity = []; String _selectedChannelId = ""; String _regionId = ""; @override void initState() { super.initState(); Provider.of(context, listen: false).balance(); if (Platform.isAndroid) { Provider.of(context, listen: false).init(context); } else if (Platform.isIOS) { Provider.of(context, listen: false).init(context); } if ((Provider.of( context, listen: false, ).userIdentity?.agent ?? false) || (Provider.of( context, listen: false, ).userIdentity?.anchor ?? false) || (Provider.of( context, listen: false, ).userIdentity?.bd ?? false) || (Provider.of( context, listen: false, ).userIdentity?.admin ?? false) || (Provider.of( context, listen: false, ).userIdentity?.manager ?? false) || (Provider.of( context, listen: false, ).userIdentity?.superAdmin ?? false) || (Provider.of( context, listen: false, ).userIdentity?.bdLeader ?? false) || (Provider.of( context, listen: false, ).userIdentity?.freightAgent ?? false) || (Provider.of( context, listen: false, ).userIdentity?.superFreightAgent ?? false)) { _hasPersmission = true; } _loadData(); } @override void didChangeDependencies() { super.didChangeDependencies(); // 注册路由观察 final route = ModalRoute.of(context); if (route is PageRoute) { routeObserver.subscribe(this, route); } } @override void didPush() { // 路由被推入时调用 _updateVisibility(true); } @override void didPopNext() { // 当从下一个页面返回时调用 _updateVisibility(true); } @override void didPushNext() { // 当推入下一个页面时调用 _updateVisibility(false); } @override void didPop() { // 路由弹出时调用 _updateVisibility(false); } void _updateVisibility(bool isVisible) { if (isVisible) { Provider.of(context, listen: false).balance(); } else {} } @override void dispose() { routeObserver.unsubscribe(this); super.dispose(); } @override Widget build(BuildContext context) { return Stack( children: [ Image.asset( "atu_images/index/at_icon_recharge_bg.png", width: ScreenUtil().screenWidth, height: ScreenUtil().screenHeight, fit: BoxFit.fill, ), Scaffold( backgroundColor: Colors.transparent, resizeToAvoidBottomInset: false, appBar: ChatVibeStandardAppBar( title: ATAppLocalizations.of(context)!.recharge, backButtonColor: Colors.white, actions: [ // GestureDetector( // child: Container( // margin: EdgeInsetsDirectional.only(end: 15.w), // child: Image.asset( // "atu_images/index/at_icon_recharge_recod.png", // width: 24.w, // height: 24.w, // ), // ), // onTap: () { // showGeneralDialog( // context: context, // barrierLabel: '', // barrierDismissible: true, // transitionDuration: Duration(milliseconds: 300), // barrierColor: Colors.transparent, // pageBuilder: ( // BuildContext context, // Animation animation, // Animation secondaryAnimation, // ) { // return GestureDetector( // behavior: HitTestBehavior.opaque, // onTap: () { // Navigator.pop(context); // setState(() {}); // }, // child: Column( // crossAxisAlignment: CrossAxisAlignment.end, // children: [ // SizedBox(height: height(68)), // Row( // children: [ // Spacer(), // GestureDetector( // child: Container( // decoration: BoxDecoration( // color: Colors.white30, // borderRadius: BorderRadius.circular(4), // ), // padding: EdgeInsets.symmetric( // horizontal: 8.w, // vertical: 3.w, // ), // child: Column( // crossAxisAlignment: // CrossAxisAlignment.start, // children: [ // SizedBox(height: 5.w), // GestureDetector( // child: text( // ATAppLocalizations.of( // context, // )!.goldListort, // textColor: Colors.white70, // fontSize: 14.sp, // ), // onTap: () { // Navigator.of(context).pop(); // ATNavigatorUtils.push( // context, // WalletRoute.goldRecord, // replace: false, // ); // }, // ), // // SizedBox(height: 5.w), // // Container( // // color: Colors.black26, // // width: 110.w, // // height: 0.5.w, // // ), // // SizedBox(height: 5.w,), // // text( // // ATAppLocalizations.of( // // context, // // )!.rechargeList, // // textColor: Colors.black38, // // fontSize: 14.sp, // // ), // SizedBox(height: 5.w), // ], // ), // ), // onTap: () {}, // ), // SizedBox(width: 10.w), // ], // ), // Expanded(child: SizedBox(width: width(1))), // ], // ), // ); // }, // ); // }, // ), ], ), body: SafeArea( top: false, child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ SizedBox(height: 25.w), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( height: 85.w, width: ScreenUtil().screenWidth * 0.9, decoration: BoxDecoration( image: DecorationImage( image: AssetImage( "atu_images/index/at_icon_wallet_bg.png", ), fit: BoxFit.fill, ), ), child: Stack( alignment: AlignmentDirectional.centerEnd, children: [ Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Row( children: [ SizedBox(width: 6.w), Image.asset( "atu_images/general/at_icon_jb.png", width: 20.w, height: 20.w, ), SizedBox(width: 5.w), text( ATAppLocalizations.of(context)!.balance, fontSize: 16.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ), ], ), SizedBox(height: 5.w), Consumer( builder: (context, ref, child) { return Row( mainAxisAlignment: MainAxisAlignment.start, children: [ SizedBox(width: 15.w), text( "${ref.myBalance}", textColor: Colors.white, fontSize: 18.sp, ), ], ); }, ), ], ), ATDebounceWidget( child: Container( margin: EdgeInsetsDirectional.only(end: 18.w), padding: EdgeInsets.symmetric( horizontal: 8.w, vertical: 5.w, ), decoration: BoxDecoration( borderRadius: BorderRadius.circular(8.w), gradient: LinearGradient( colors: [ Color(0xffFFECD0), Color(0xffEAB66B), ], begin: Alignment.topCenter, end: Alignment.bottomCenter, ), ), child: text( ATAppLocalizations.of(context)!.rechargeRecords, fontSize: 12.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ), ), onTap: () { ATNavigatorUtils.push( context, WalletRoute.goldRecord, replace: false, ); }, ), ], ), ), ], ), SizedBox(height: 25.w), Expanded( child: Container( padding: EdgeInsets.symmetric(horizontal: 8.w), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only( topLeft: Radius.circular(8.w), topRight: Radius.circular(8.w), ), ), child: SingleChildScrollView( child: Column( children: [ SizedBox(height: 8.w), _hasPersmission ? Row( children: [ SizedBox(width: 5.w), text( ATAppLocalizations.of( context, )!.selectACountry, textColor: Colors.black, fontSize: 13.sp, ), Spacer(), GestureDetector( child: Container( alignment: Alignment.center, width: 65.w, height: 23.w, decoration: BoxDecoration( image: DecorationImage( image: AssetImage( "atu_images/general/at_icon_pay_select_country_bg.png", ), fit: BoxFit.fill, ), ), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ netImage( url: _selectedCountry ?.country ?.nationalFlag ?? "", borderRadius: BorderRadius.all( Radius.circular(3.w), ), width: 19.w, height: 14.w, ), SizedBox(width: 5.w), Container( constraints: BoxConstraints( maxWidth: 32.w, ), child: text( _selectedCountry ?.country ?.aliasName ?? "", textColor: Colors.white, fontSize: 9.sp, fontWeight: FontWeight.bold, ), ), ], ), ), onTap: () { SmartDialog.show( tag: "showPaySelectCountryDialog", alignment: Alignment.bottomCenter, debounce: true, animationType: SmartAnimationType.fade, builder: (_) { return PaySelectCountryPage( _countryList, _selectedCountry, (se) { if (_selectedCountry?.id != se.id) { _selectedCountry = se; setState(() {}); refreshWebPayCommodity(); } }, ); }, ); }, ), SizedBox(width: 10.w), ], ) : Container(), SizedBox(height: 8.w), Column( spacing: 10.w, children: [ if (_hasPersmission) ATDebounceWidget( child: Stack( children: [ Container( margin: EdgeInsets.symmetric( horizontal: 8.w, ), height: 55.w, padding: EdgeInsets.symmetric( horizontal: 8.w, ), decoration: BoxDecoration( borderRadius: BorderRadius.circular( 8.w, ), color: _selectedChannelId == "-1" ? ChatVibeTheme.primaryLight .withOpacity(0.1) : Colors.white, border: _selectedChannelId == "-1" ? Border.all( color: ChatVibeTheme .primaryLight, ) : Border.all( color: Colors.white, ), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity( 0.2, ), spreadRadius: 2, blurRadius: 3, offset: Offset( 0, 1, ), // changes position of shadow ), ], ), child: Row( children: [ Image.asset( "atu_images/general/at_icon_logo.png", width: 35.w, height: 35.w, ), SizedBox(width: 6.w), text( "Aslan", textColor: Colors.black, fontSize: 16.sp, fontWeight: FontWeight.bold, ), SizedBox(width: 6.w), text( ATAppLocalizations.of( context, )!.officialRechargeAgent, textColor: Colors.black, fontSize: 13.sp, ), ], ), ), PositionedDirectional( end: 0, child: Container( margin: EdgeInsets.symmetric( horizontal: 8.w, ), padding: EdgeInsets.symmetric( horizontal: 6.w, vertical: 2.w, ), decoration: BoxDecoration( borderRadius: BorderRadiusDirectional.only( topEnd: Radius.circular(8.w), bottomStart: Radius.circular( 8.w, ), ), gradient: LinearGradient( colors: [ Color(0xffFF3639), Color(0xffFF787A), ], ), ), child: text( ATAppLocalizations.of( context, )!.biggestDiscount, textColor: Colors.white, fontSize: 12.sp, ), ), ), ], ), onTap: () { setState(() { _selectedChannelId = "-1"; }); ATNavigatorUtils.push( context, WalletRoute.agentList, replace: false, ); }, ), if (_hasPersmission) Column( spacing: 10.w, children: List.generate(_channels.length, ( index, ) { return GestureDetector( child: Container( margin: EdgeInsets.symmetric( horizontal: 8.w, ), height: 55.w, padding: EdgeInsets.symmetric( horizontal: 12.w, ), decoration: BoxDecoration( borderRadius: BorderRadius.circular( 8.w, ), color: _selectedChannelId == _channels[index] .channel ?.id ? ChatVibeTheme.primaryLight .withOpacity(0.1) : Colors.white, border: _selectedChannelId == _channels[index] .channel ?.id ? Border.all( color: ChatVibeTheme .primaryLight, ) : Border.all( color: Colors.white, ), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity( 0.2, ), spreadRadius: 2, blurRadius: 3, offset: Offset( 0, 1, ), // changes position of shadow ), ], ), child: Row( children: [ netImage( url: _channels[index] .channel ?.channelIcon ?? "", width: 35.w, height: 35.w, fit: BoxFit.contain, ), SizedBox(width: 6.w), text( _channels[index] .channel ?.channelName ?? "", textColor: Colors.black, fontSize: 16.sp, fontWeight: FontWeight.bold, ), ], ), ), onTap: () { setState(() { _selectedChannelId = _channels[index].channel?.id ?? ""; }); SmartDialog.show( tag: "showPayPriceItemDialog", alignment: Alignment.bottomCenter, debounce: true, animationType: SmartAnimationType.fade, builder: (_) { return ATPayCustomPriceItemPage( _channels[index], _commodity, ); }, ); }, ); }), ), if (Platform.isAndroid) GestureDetector( child: Container( margin: EdgeInsets.symmetric( horizontal: 8.w, ), height: 55.w, padding: EdgeInsets.symmetric( horizontal: 12.w, ), decoration: BoxDecoration( borderRadius: BorderRadius.circular(8.w), color: _selectedChannelId == "-2" ? ChatVibeTheme.primaryLight .withOpacity(0.1) : Colors.white, border: _selectedChannelId == "-2" ? Border.all( color: ChatVibeTheme.primaryLight, ) : Border.all(color: Colors.white), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.2), spreadRadius: 2, blurRadius: 3, offset: Offset( 0, 1, ), // changes position of shadow ), ], ), child: Row( children: [ Image.asset( "atu_images/general/at_icon_google_pay.png", width: 35.w, height: 35.w, fit: BoxFit.contain, ), SizedBox(width: 6.w), text( ATAppLocalizations.of( context, )!.googlePay, textColor: Colors.black, fontSize: 16.sp, fontWeight: FontWeight.bold, ), ], ), ), onTap: () { setState(() { _selectedChannelId = "-2"; }); SmartDialog.show( tag: "showPayPriceItemDialog", alignment: Alignment.bottomCenter, debounce: true, animationType: SmartAnimationType.fade, builder: (_) { return ATPayGoogleApplePriceItemPage( selectedChannelId: "-2", ); }, ); }, ), if (Platform.isIOS) GestureDetector( child: Container( margin: EdgeInsets.symmetric( horizontal: 8.w, ), height: 55.w, padding: EdgeInsets.symmetric( horizontal: 12.w, ), decoration: BoxDecoration( borderRadius: BorderRadius.circular(8.w), color: _selectedChannelId == "-3" ? ChatVibeTheme.primaryLight .withOpacity(0.1) : Colors.white, border: _selectedChannelId == "-3" ? Border.all( color: ChatVibeTheme.primaryLight, ) : Border.all(color: Colors.white), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.2), spreadRadius: 2, blurRadius: 3, offset: Offset( 0, 1, ), // changes position of shadow ), ], ), child: Row( children: [ Image.asset( "atu_images/general/at_icon_apple_pay.png", width: 35.w, height: 35.w, fit: BoxFit.contain, ), SizedBox(width: 6.w), text( ATAppLocalizations.of( context, )!.appStore, textColor: Colors.black, fontSize: 16.sp, fontWeight: FontWeight.bold, ), ], ), ), onTap: () { setState(() { _selectedChannelId = "-3"; }); SmartDialog.show( tag: "showPayPriceItemDialog", alignment: Alignment.bottomCenter, debounce: true, animationType: SmartAnimationType.fade, builder: (_) { return ATPayGoogleApplePriceItemPage( selectedChannelId: "-3", ); }, ); }, ), SizedBox(height: 5.w), ], ), ], ), ), ), ), ], ), ), ), ], ); } void _loadData() async { String type = "GOLD"; if (Provider.of( context, listen: false, ).userIdentity?.freightAgent ?? false) { type = "FREIGHT_GOLD"; } else if (Provider.of( context, listen: false, ).userIdentity?.superFreightAgent ?? false) { type = "FREIGHT_GOLD_SUPER"; } try { ATLoadingManager.exhibitOperation(); var webPayUserProfileRes = await AccountRepository().webPayUserProfile( userId: AccountStorage().getCurrentUser()?.userProfile?.id ?? "", account: AccountStorage().getCurrentUser()?.userProfile?.account ?? "", type: type, ); _countryList = webPayUserProfileRes.countryList ?? []; _selectedCountry = webPayUserProfileRes.countryList?.first; String payCountryId = _selectedCountry?.id ?? ""; _regionId = webPayUserProfileRes.regionId ?? ""; setState(() {}); var webPayCommodityRes = await AccountRepository().webPayCommodity( payCountryId: payCountryId, type: type, regionId: webPayUserProfileRes.regionId, ); _channels = webPayCommodityRes.channels ?? []; _commodity = webPayCommodityRes.commodity ?? []; setState(() {}); ATLoadingManager.veilRoutine(); } catch (e) { ATLoadingManager.veilRoutine(); } } void refreshWebPayCommodity() async { ATLoadingManager.exhibitOperation(); String type = "GOLD"; if (Provider.of( context, listen: false, ).userIdentity?.freightAgent ?? false) { type = "FREIGHT_GOLD"; } else if (Provider.of( context, listen: false, ).userIdentity?.superFreightAgent ?? false) { type = "FREIGHT_GOLD_SUPER"; } try { var webPayCommodityRes = await AccountRepository().webPayCommodity( payCountryId: _selectedCountry?.id, type: type, regionId: _regionId, ); _selectedChannelId = ""; _channels = webPayCommodityRes.channels ?? []; _commodity = webPayCommodityRes.commodity ?? []; setState(() {}); ATLoadingManager.veilRoutine(); } catch (_) { ATLoadingManager.veilRoutine(); } } }