import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:aslan/app_localizations.dart'; import 'package:aslan/chatvibe_ui/components/at_compontent.dart'; import 'package:aslan/chatvibe_ui/components/text/at_text.dart'; import 'package:aslan/chatvibe_core/utilities/at_date_utils.dart'; import 'package:aslan/chatvibe_features/family/family_route.dart'; import 'package:aslan/chatvibe_features/index/main_route.dart'; import 'package:aslan/chatvibe_features/user/settings/settings_route.dart'; import 'package:aslan/chatvibe_managers/rtc_manager.dart'; import 'package:marquee/marquee.dart'; import 'package:provider/provider.dart'; import 'package:aslan/chatvibe_ui/components/at_tts.dart'; import 'package:aslan/chatvibe_core/constants/at_global_config.dart'; import 'package:aslan/chatvibe_core/routes/at_fluro_navigator.dart'; import 'package:aslan/chatvibe_data/sources/local/user_manager.dart'; import 'package:aslan/chatvibe_managers/room_manager.dart'; import 'package:aslan/chatvibe_managers/user_profile_manager.dart'; import 'package:aslan/chatvibe_features/home/coupon/coupon_route.dart'; import 'package:aslan/chatvibe_features/store/store_route.dart'; import 'package:aslan/chatvibe_features/wallet/wallet_route.dart'; import '../../../chatvibe_data/models/enum/at_vip_type.dart'; ///抽屉 class MyDrawer extends StatefulWidget { @override _MyDrawerState createState() => _MyDrawerState(); } class _MyDrawerState extends State { @override void initState() { super.initState(); Provider.of(context, listen: false).getMyRoom(); Provider.of(context, listen: false).getUserIdentity(); Provider.of( context, listen: false, ).getMyUserInfo(needLoadUserCountGuard: false, needRefreshFamily: true); } @override void dispose() { super.dispose(); } @override Widget build(BuildContext context) { return Container( padding: EdgeInsetsDirectional.only( top: 42.w, ).copyWith(start: 8.w, end: 8.w), decoration: BoxDecoration( image: DecorationImage( image: AssetImage("atu_images/index/at_icon_drawer_bg.png"), fit: BoxFit.fill, ), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ GestureDetector( behavior: HitTestBehavior.opaque, child: Container( padding: EdgeInsetsDirectional.symmetric(vertical: 8.w), decoration: BoxDecoration( color: Colors.white12, borderRadius: BorderRadius.all(Radius.circular(10.w)), border: Border.all(color: Colors.white, width: 0.6.w), ), child: Row( children: [ SizedBox(width: 10.w), Consumer( builder: (context, ref, child) { return head( url: AccountStorage() .getCurrentUser() ?.userProfile! .userAvatar ?? "", width: 58.w, headdress: AccountStorage() .getCurrentUser() ?.userProfile ?.getHeaddress() ?.sourceUrl, ); }, ), SizedBox(width: 3.w), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ chatvibeNickNameText( maxWidth: 115.w, AccountStorage() .getCurrentUser() ?.userProfile ?.userNickname ?? "", fontSize: 16.sp, fontWeight: FontWeight.bold, type: AccountStorage() .getCurrentUser() ?.userProfile ?.getVIP() ?.name ?? "", needScroll: (AccountStorage() .getCurrentUser() ?.userProfile ?.userNickname ?.characters .length ?? 0) > 10, ), GestureDetector( child: Container( padding: EdgeInsets.symmetric(vertical: 8.w), decoration: BoxDecoration( image: DecorationImage( image: AssetImage( (AccountStorage() .getCurrentUser() ?.userProfile ?.hasSpecialId() ?? false) ? "atu_images/general/at_icon_special_id_bg.png" : "atu_images/general/at_icon_id_bg.png", ), fit: BoxFit.fitWidth, ), ), child: Row( textDirection: TextDirection.ltr, children: [ SizedBox(width: 38.w), text( "${AccountStorage().getCurrentUser()?.userProfile?.getID()}", fontSize: 12.sp, textColor: Colors.white, fontWeight: FontWeight.bold, ), SizedBox(width: 5.w), Image.asset( "atu_images/room/at_icon_user_card_copy_id.png", width: 12.w, height: 12.w, ), SizedBox(width: 8.w), ], ), ), onTap: () { Clipboard.setData( ClipboardData( text: AccountStorage() .getCurrentUser() ?.userProfile ?.getID() ?? "", ), ); ATTts.show( ATAppLocalizations.of(context)!.copiedToClipboard, ); }, ), ], ), Spacer(), Icon( ATGlobalConfig.lang == "ar" ? Icons.keyboard_arrow_left : Icons.keyboard_arrow_right, size: 25.w, color: Colors.white, ), SizedBox(width: 12.w), ], ), ), onTap: () { ATNavigatorUtils.push( context, "${MainRoute.person}?isMe=true&tageId=${AccountStorage().getCurrentUser()?.userProfile?.id}", replace: false, ); }, ), SizedBox(height: 10.w), _buildMyRoom(), SizedBox(height: 5.w), Expanded( child: SingleChildScrollView( child: Column( children: [ Row( crossAxisAlignment: CrossAxisAlignment.end, children: [ SizedBox(width: 10.w), Expanded( child: GestureDetector( child: Container( height: 59.w, decoration: BoxDecoration( image: DecorationImage( image: AssetImage("atu_images/index/at_icon_bag.png"), fit: BoxFit.contain, ), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox(height: 39.w), Row( textDirection: TextDirection.ltr, children: [ SizedBox(width: 10.w), Image.asset( "atu_images/general/at_icon_jb.png", width: 18.w, height: 18.w, ), Consumer( builder: (context, ref, child) { return text( ref.myBalance > 1000 ? "${(ref.myBalance / 1000).toStringAsFixed(2)}k" : "${ref.myBalance}", fontSize: 11.sp, textColor: Colors.white, fontWeight: FontWeight.bold, ); }, ), ], ), ], ), ), onTap: () { ATNavigatorUtils.push( context, WalletRoute.recharge, replace: false, ); }, ), ), SizedBox(width: 5.w), Expanded( child: GestureDetector( child: SizedBox( height: 68.w, child: Consumer( builder: (context, ref, child) { return Stack( alignment: Alignment.bottomCenter, children: [ Container( height: 47.w, decoration: BoxDecoration( image: DecorationImage( image: AssetImage(_getVIPTagIcon()), fit: BoxFit.contain, ), ), child: Column( children: [ SizedBox(height: 27.w), AccountStorage().getVIPExpireTime() != "0" ? Row( textDirection: TextDirection.ltr, children: [ SizedBox(width: 12.w), text( "${ATMDateUtils.evaluateDaysDifferenceFunction(DateTime.now(), DateTime.fromMillisecondsSinceEpoch(int.parse(AccountStorage().getVIPExpireTime())))} ${ATAppLocalizations.of(context)!.days}", fontSize: 11.sp, textColor: Colors.white, fontWeight: FontWeight.bold, ), ], ) : Container(), ], ), ), Positioned( top: 0, right: 2.w, child: _getVIPIcon().isNotEmpty ? Image.asset( width: 60.w, height: 60.w, _getVIPIcon(), ) : Container(), ), ], ); }, ), ), onTap: () { ATNavigatorUtils.push( context, MainRoute.vipList, replace: false, ); }, ), ), SizedBox(width: 10.w), ], ), SizedBox(height: 10.w), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ SizedBox(width: 2.w), _buildItem2( "atu_images/index/at_icon_shop.png", ATAppLocalizations.of(context)!.store, () { ATNavigatorUtils.push( context, StoreRoute.list, replace: false, ); }, ), _buildItem2( "atu_images/index/at_icon_level.png", ATAppLocalizations.of(context)!.level, () { ATNavigatorUtils.push( context, MainRoute.levelList, replace: false, ); }, ), _buildItem2( "atu_images/index/at_icon_my_items.png", ATAppLocalizations.of(context)!.items, () { ATNavigatorUtils.push( context, StoreRoute.bags, replace: false, ); }, ), _buildItem2( "atu_images/index/at_icon_task.png", ATAppLocalizations.of(context)!.task, () { ATNavigatorUtils.push( context, MainRoute.taskList, replace: false, ); }, ), SizedBox(width: 2.w), ], ), SizedBox(height: 5.w), _buildItem( "atu_images/index/at_icon_paid.png", ATAppLocalizations.of(context)!.getPaidToRefer, () { ATNavigatorUtils.push( context, "${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.inviteNewUserUrl)}&showTitle=false", replace: false, ); }, ), _buildItem( "atu_images/index/at_icon_coupon.png", ATAppLocalizations.of(context)!.coupon, () { ATNavigatorUtils.push( context, CouponRoute.couponList, replace: false, ); }, ), _buildItem( "atu_images/index/at_icon_medals.png", ATAppLocalizations.of(context)!.medals, () { ATNavigatorUtils.push( context, MainRoute.medalsList, replace: false, ); }, ), _buildItem( "atu_images/index/at_icon_honor.png", ATAppLocalizations.of(context)!.honor, () { ATNavigatorUtils.push( context, MainRoute.honorList, replace: false, ); }, ), Consumer( builder: (context, ref, child) { return (ref.userIdentity?.anchor ?? false) ? (ref.userIdentity?.agent ?? false ? _buildItem( "atu_images/index/at_icon_agent_center.png", ATAppLocalizations.of(context)!.agentCenter, () { ATNavigatorUtils.push( context, "${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.agencyCenterUrl)}&showTitle=false", replace: false, ); }, ) : _buildItem( "atu_images/index/at_icon_host_center.png", ATAppLocalizations.of(context)!.hostCenter, () { ATNavigatorUtils.push( context, "${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.hostCenterUrl)}&showTitle=false", replace: false, ); }, )) : _buildItem( "atu_images/index/at_icon_become_host_center.png", ATAppLocalizations.of(context)!.becomeHost, () { ATNavigatorUtils.push( context, "${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.anchorAgentUrl)}&showTitle=false", replace: false, ); }, ); }, ), Consumer( builder: (context, ref, child) { return (ref.userIdentity?.admin ?? false) ? Container() : ((ref.userIdentity?.bdLeader ?? false) ? _buildItem( "atu_images/index/at_icon_bd_leader.png", ATAppLocalizations.of(context)!.bdLeader, () { ATNavigatorUtils.push( context, "${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.bdLeaderUrl)}&showTitle=false", replace: false, ); }, ) : ((ref.userIdentity?.bd ?? false) ? _buildItem( "atu_images/index/at_icon_bd_center.png", ATAppLocalizations.of(context)!.bdCenter, () { ATNavigatorUtils.push( context, "${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.bdCenterUrl)}&showTitle=false", replace: false, ); }, ) : Container())); }, ), Consumer( builder: (context, ref, child) { return (ref.userIdentity?.freightAgent ?? false) ? _buildItem( "atu_images/index/at_icon_recharge_agency.png", ATAppLocalizations.of(context)!.rechargeAgency, () { ATNavigatorUtils.push( context, "${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.coinSellerUrl)}&showTitle=false", replace: false, ); }, ) : Container(); }, ), Consumer( builder: (context, ref, child) { return (ref.userIdentity?.admin ?? false) ? _buildItem( "atu_images/index/at_icon_admin_center.png", ATAppLocalizations.of(context)!.adminCenter, () { ATNavigatorUtils.push( context, "${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.adminUrl)}&showTitle=false", replace: false, ); }, ) : Container(); }, ), Consumer( builder: (context, ref, child) { return AccountStorage() .getCurrentUser() ?.userProfile ?.familyId == null ? _buildItem( "atu_images/index/at_icon_family.png", ATAppLocalizations.of(context)!.joinFamily, () { ATNavigatorUtils.push( context, FamilyRoute.familyList, replace: false, ); }, ) : _buildItem( "atu_images/index/at_icon_family.png", ATAppLocalizations.of(context)!.family, () { ATNavigatorUtils.push( context, "${FamilyRoute.familyInfo}?familyId=${AccountStorage().getCurrentUser()?.userProfile?.familyId ?? 0}", replace: false, ); }, ); }, ), ], ), ), ), // _buildItem("images/index/at_icon_task.png", "Task"), // Divider(color: Colors.black12, thickness: 0.5, height: 28.w), Divider(color: Colors.black12, thickness: 0.5, height: 28.w), GestureDetector( child: Container( alignment: AlignmentDirectional.center, child: Column( children: [ Image.asset( "atu_images/index/at_icon_settings.png", width: 30.w, height: 30.w, color: Colors.white, ), SizedBox(height: 3.w), text( ATAppLocalizations.of(context)!.settings, textColor: Colors.white, fontSize: 16.sp, fontWeight: FontWeight.w600, ), ], ), ), onTap: () { ATNavigatorUtils.push( context, SettingsRoute.settings, replace: false, ); }, ), SizedBox(height: 15.w), ], ), ); } _buildMyRoom() { return Consumer( builder: (_, provider, __) { return provider.myRoom != null ? GestureDetector( behavior: HitTestBehavior.opaque, child: Container( padding: EdgeInsetsDirectional.symmetric(vertical: 8.w), decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(10.w)), color: Colors.white12, border: Border.all(color: Colors.white, width: 0.6.w), ), child: Row( children: [ SizedBox(width: 10.w), netImage( url: provider.myRoom?.roomCover ?? "", borderRadius: BorderRadius.all(Radius.circular(8.w)), width: 48.w, ), SizedBox(width: 10.w), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( constraints: BoxConstraints( maxWidth: 115.w, maxHeight: 24.w, ), child: (provider.myRoom?.roomName?.length ?? 0) > 10 ? Marquee( text: provider.myRoom?.roomName ?? "", style: TextStyle( fontSize: 16.sp, color: Colors.white, fontWeight: FontWeight.bold, decoration: TextDecoration.none, ), scrollAxis: Axis.horizontal, crossAxisAlignment: CrossAxisAlignment.start, blankSpace: 40.0, velocity: 40.0, pauseAfterRound: Duration(seconds: 1), accelerationDuration: Duration( seconds: 1, ), accelerationCurve: Curves.easeOut, decelerationDuration: Duration( milliseconds: 500, ), decelerationCurve: Curves.easeOut, ) : Text( provider.myRoom?.roomName ?? "", maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 16.sp, color: Colors.white, fontWeight: FontWeight.bold, decoration: TextDecoration.none, ), ), ), text( provider.myRoom?.roomDesc ?? "", fontSize: 14.sp, textColor: Colors.white, ), ], ), ), Icon( ATGlobalConfig.lang == "ar" ? Icons.keyboard_arrow_left : Icons.keyboard_arrow_right, size: 25.w, color: Colors.white, ), SizedBox(width: 12.w), ], ), ), onTap: () { String roomId = Provider.of( context, listen: false, ).myRoom?.id ?? ""; Provider.of( context, listen: false, ).joinRoom(context, roomId); }, ) : GestureDetector( child: Row( children: [ SizedBox(width: 10.w), Image.asset( "atu_images/index/at_icon_add_room.png", width: 36.w, height: 36.w, ), SizedBox(width: 10.w), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ text( ATAppLocalizations.of(context)!.roomName, fontSize: 14.sp, textColor: Colors.white, fontWeight: FontWeight.bold, ), text( ATAppLocalizations.of(context)!.startVoiceParty, fontSize: 13.sp, textColor: Colors.white, ), ], ), SizedBox(width: 12.w), ], ), onTap: () { provider.createRoom(context); }, ); }, ); } _buildItem(String icon, String title, Function() onTap) { return GestureDetector( child: Column( children: [ SizedBox(height: 10.w), Container( alignment: AlignmentDirectional.centerStart, height: 48.w, decoration: BoxDecoration( image: DecorationImage( image: AssetImage("atu_images/index/at_icon_my_drawer_item_bg.png"), fit: BoxFit.fill, ), ), child: Column( mainAxisSize: MainAxisSize.min, children: [ Row( children: [ SizedBox(width: 10.w), Image.asset( icon, width: 26.w, height: 26.w, color: Colors.white, ), SizedBox(width: 10.w), Expanded( child: text( title, textColor: Colors.white, fontSize: 17.sp, fontWeight: FontWeight.w600, ), ), Icon( ATGlobalConfig.lang == "ar" ? Icons.keyboard_arrow_left : Icons.keyboard_arrow_right, color: Colors.white, size: 15.w, ), SizedBox(width: 12.w), ], ), ], ), ), ], ), onTap: () { onTap(); }, ); } _buildItem2(String icon, String title, Function() onTap) { return GestureDetector( child: Column( mainAxisSize: MainAxisSize.min, children: [ Image.asset(icon, width: 35.w, height: 35.w), SizedBox(height: 5.w), text( title, textColor: Colors.white, fontSize: 15.sp, fontWeight: FontWeight.w600, ), SizedBox(width: 12.w), ], ), onTap: () { onTap(); }, ); } _getVIPTagIcon() { var vip = AccountStorage().getVIP(); if (vip != null) { if (vip.name == ATVIPType.VISCOUNT.name) { return "atu_images/vip/at_icon_vip_1.png"; } else if (vip.name == ATVIPType.EARL.name) { return "atu_images/vip/at_icon_vip_2.png"; } else if (vip.name == ATVIPType.MARQUIS.name) { return "atu_images/vip/at_icon_vip_3.png"; } else if (vip.name == ATVIPType.DUKE.name) { return "atu_images/vip/at_icon_vip_4.png"; } else if (vip.name == ATVIPType.KING.name) { return "atu_images/vip/at_icon_vip_5.png"; }else if (vip.name == ATVIPType.EMPEROR.name) { return "atu_images/vip/at_icon_vip_6.png"; } } return "atu_images/vip/at_icon_vip_no.png"; } String _getVIPIcon() { String name = AccountStorage().getVIP()?.name ?? ""; if (name == ATVIPType.VISCOUNT.name) { return "atu_images/vip/at_icon_vip1_ic.webp"; } else if (name == ATVIPType.EARL.name) { return "atu_images/vip/at_icon_vip2_ic.webp"; } else if (name == ATVIPType.MARQUIS.name) { return "atu_images/vip/at_icon_vip3_ic.webp"; } else if (name == ATVIPType.DUKE.name) { return "atu_images/vip/at_icon_vip4_ic.webp"; } else if (name == ATVIPType.KING.name) { return "atu_images/vip/at_icon_vip5_ic.webp"; } else if (name == ATVIPType.EMPEROR.name) { return "atu_images/vip/at_icon_vip6_ic.webp"; } return ""; } }