2026-07-10 20:31:52 +08:00

1167 lines
41 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:convert';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter_debouncer/flutter_debouncer.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.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_ui/components/at_tts.dart';
import 'package:aslan/chatvibe_ui/theme/chatvibe_theme.dart';
import 'package:aslan/chatvibe_core/constants/at_global_config.dart';
import 'package:aslan/chatvibe_core/config/business_logic_strategy.dart';
import 'package:aslan/chatvibe_core/utilities/at_gift_vap_svga_manager.dart';
import 'package:aslan/chatvibe_core/utilities/at_room_utils.dart';
import 'package:aslan/chatvibe_data/sources/local/user_manager.dart';
import 'package:aslan/chatvibe_data/sources/repositories/room_repository_imp.dart';
import 'package:aslan/chatvibe_domain/models/res/login_res.dart';
import 'package:aslan/main.dart';
import 'package:provider/provider.dart';
import 'package:aslan/chatvibe_core/constants/at_room_msg_type.dart';
import 'package:aslan/chatvibe_core/constants/at_screen.dart';
import 'package:aslan/chatvibe_core/routes/at_fluro_navigator.dart';
import 'package:aslan/chatvibe_data/sources/local/floating_screen_manager.dart';
import 'package:aslan/chatvibe_domain/models/res/gift_res.dart';
import 'package:aslan/chatvibe_domain/models/res/mic_res.dart';
import 'package:aslan/chatvibe_managers/app_general_manager.dart';
import 'package:aslan/chatvibe_managers/gift_system_manager.dart';
import 'package:aslan/chatvibe_managers/rtc_manager.dart';
import 'package:aslan/chatvibe_managers/rtm_manager.dart';
import 'package:aslan/chatvibe_managers/user_profile_manager.dart';
import 'package:aslan/chatvibe_ui/widgets/room/give_room_luck_page.dart';
import 'package:aslan/chatvibe_ui/widgets/room/room_msg_item.dart';
import 'package:aslan/chatvibe_features/wallet/wallet_route.dart';
import 'package:aslan/chatvibe_features/gift/gift_tab_page.dart';
import '../../chatvibe_data/models/enum/at_gift_type.dart';
import '../../chatvibe_data/models/message/at_floating_message.dart';
import '../../chatvibe_domain/usecases/at_fixed_width_tabIndicator.dart';
class GiftPage extends StatefulWidget {
ChatVibeUserProfile? toUser;
final int initialIndex;
final bool isChatGift;
final void Function(ChatVibeGiftRes gift, int number)? onChatGiftSend;
GiftPage({
super.key,
this.toUser,
this.initialIndex = 0,
this.isChatGift = false,
this.onChatGiftSend,
});
@override
_GiftPageState createState() => _GiftPageState();
}
class _GiftPageState extends State<GiftPage>
with SingleTickerProviderStateMixin {
TabController? _tabController;
/// 业务逻辑策略访问器
BusinessLogicStrategy get _strategy => ATGlobalConfig.businessLogicStrategy;
// int checkedIndex = 0;
ChatVibeGiftRes? checkedGift;
RtcProvider? rtcProvider;
bool isAll = false;
List<HeadSelect> listMai = [];
bool noShowNumber = false;
///选中人员
Set<String> set = {};
///数量的箭头是否朝上
bool isNumberUp = true;
///数量
int number = 1;
int giveType = 1;
int giftType = 0;
Debouncer debouncer = Debouncer();
@override
void initState() {
super.initState();
rtcProvider = Provider.of<RtcProvider>(context, listen: false);
Provider.of<AppGeneralManager>(context, listen: false).giftList();
// Provider.of<AppGeneralManager>(context, listen: false).giftActivityList();
// Provider.of<GeneralProvider>(context, listen: false).giftBackpack();
Provider.of<ChatVibeUserProfileManager>(context, listen: false).balance();
rtcProvider?.roomWheatMap.forEach((k, v) {
if (v.user != null) {
if (v.user?.id == AccountStorage().getCurrentUser()?.userProfile?.id) {
listMai.add(HeadSelect(true, v));
} else {
listMai.add(HeadSelect(false, v));
}
}
isAll = true;
for (var mai in listMai) {
if (!mai.isSelect) {
isAll = false;
}
}
});
}
@override
void dispose() {
_tabController?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Consumer<AppGeneralManager>(
builder: (context, ref, child) {
final giftTabTypes = _giftTabTypes(ref);
final tabs = giftTabTypes.map(_buildGiftTab).toList();
final pages =
giftTabTypes
.map(
(giftTab) => GiftTabPage(giftTab, (int checkedI) {
_selectGift(giftTab, checkedI);
}),
)
.toList();
_syncTabController(giftTabTypes.length);
return SafeArea(
top: false,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
_buildGiftHead(),
ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(12.0),
topRight: Radius.circular(12.0),
),
child: Container(
color: Color(0xff262533),
constraints: BoxConstraints(maxHeight: 430.w),
child: Column(
children: [
SizedBox(height: 12.w),
if (!widget.isChatGift)
Row(
children: [
SizedBox(width: 8.w),
widget.toUser == null
? Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children:
listMai
.map((e) => _maiHead(e))
.toList(),
),
),
)
: Stack(
alignment: AlignmentDirectional.center,
children: [
Container(
padding: EdgeInsets.all(2.w),
child: netImage(
url: widget.toUser?.userAvatar ?? "",
width: 26.w,
defaultImg:
_strategy
.getMePageDefaultAvatarImage(),
shape: BoxShape.circle,
),
),
widget.toUser == null
? PositionedDirectional(
bottom: 0,
end: 0,
child: Image.asset(
"atu_images/login/at_icon_login_ser_select.png",
width: 10.w,
height: 10.w,
),
)
: Container(),
],
),
widget.toUser == null
? Builder(
builder: (ct) {
return GestureDetector(
child: Image.asset(
isAll
? "atu_images/room/at_icon_gift_all_en.png"
: "atu_images/room/at_icon_gift_all_no.png",
width: 28.w,
height: 28.w,
),
onTap: () {
isAll = !isAll;
for (var mai in listMai) {
mai.isSelect = isAll;
}
setState(() {});
// showGiveTypeDialog(ct);
},
);
},
)
: Container(),
SizedBox(width: 12.w),
],
),
Row(
children: [
SizedBox(width: 5.w),
Expanded(
child: Container(
height: 28.w,
child:
tabs.isEmpty
? Container()
: TabBar(
tabAlignment: TabAlignment.start,
labelPadding: EdgeInsets.symmetric(
horizontal: 8.w,
),
labelColor: Color(0xffFFD800),
indicatorWeight: 0,
isScrollable: true,
indicator: ATFixedWidthTabIndicator(
width: 15.w,
gradient: LinearGradient(
colors: [
Color(0xffFFA500),
Color(0xffFFD700),
],
),
),
unselectedLabelColor: Colors.white54,
labelStyle: TextStyle(fontSize: 14.sp),
unselectedLabelStyle: TextStyle(
fontSize: 12.sp,
),
indicatorColor: Colors.transparent,
dividerColor: Colors.transparent,
controller: _tabController,
tabs: tabs,
),
),
),
SizedBox(width: 5.w),
],
),
Expanded(
child:
pages.isEmpty
? mainEmpty(
textColor: Colors.white54,
msg: ATAppLocalizations.of(context)!.noData,
)
: TabBarView(
physics: NeverScrollableScrollPhysics(),
controller: _tabController,
children: pages,
),
),
Row(
children: [
SizedBox(width: 15.w),
GestureDetector(
onTap: () {
SmartDialog.dismiss(tag: "showGiftControl");
ATNavigatorUtils.push(
navigatorKey.currentState!.context,
WalletRoute.recharge,
replace: false,
);
},
child: Container(
padding: EdgeInsets.symmetric(
vertical: 8.w,
horizontal: 8.w,
),
width: 120.w,
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.circular(18),
),
child: Row(
children: [
Image.asset(
_strategy.getGiftPageGoldCoinIcon(),
width: 14.w,
height: 14.w,
),
SizedBox(width: 5.w),
Consumer<ChatVibeUserProfileManager>(
builder: (context, ref, child) {
return Expanded(
child: text(
"${ref.myBalance}",
fontSize: 12.sp,
),
);
},
),
SizedBox(width: 5.w),
Icon(
Icons.arrow_forward_ios,
color: Colors.white,
size: 14.w,
),
],
),
),
),
Spacer(),
Builder(
builder: (ct) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
if (noShowNumber) {
return;
}
isNumberUp = false;
_showNumber(ct);
setState(() {});
},
child: Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.circular(18),
),
child: Row(
children: [
SizedBox(width: 10.w),
text("$number", fontSize: 12.sp),
Icon(
isNumberUp
? Icons.keyboard_arrow_up
: Icons.keyboard_arrow_down,
color: Colors.white,
size: 20.w,
),
SizedBox(width: 5.w),
GestureDetector(
onTap: () {
giveGifts();
},
child: Container(
padding: EdgeInsets.symmetric(
vertical: 8.w,
horizontal: 20.w,
),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xffFFD800),
Color(0xffFF9500),
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
borderRadius: BorderRadius.circular(
18,
),
),
child: text(
ATAppLocalizations.of(
context,
)!.send,
fontSize: 14.sp,
),
),
),
],
),
),
);
},
),
SizedBox(width: 15.w),
],
),
SizedBox(height: 15.w),
],
),
),
),
],
),
);
},
);
}
List<String> _giftTabTypes(AppGeneralManager ref) {
return ref.giftTabs.where((giftTab) {
return !widget.isChatGift || giftTab != ATGiftType.LUCKY_GIFT.name;
}).toList();
}
void _syncTabController(int length) {
if (length == 0) {
_tabController?.dispose();
_tabController = null;
return;
}
if (_tabController?.length == length) {
return;
}
final oldIndex = _tabController?.index ?? widget.initialIndex;
_tabController?.dispose();
_tabController = TabController(
length: length,
vsync: this,
initialIndex: oldIndex.clamp(0, length - 1).toInt(),
);
}
Tab _buildGiftTab(String giftTab) {
if (giftTab == ATGiftType.LUCKY_GIFT.name) {
return Tab(
child: Directionality(
textDirection: TextDirection.ltr,
child: Stack(
clipBehavior: Clip.none,
children: [
Padding(
padding: EdgeInsets.only(right: 10.w),
child: Text(_giftTabTitle(giftTab)),
),
Positioned(
top: -6.w,
right: -3.w,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: _showLuckyGiftHelpDialog,
child: Icon(Icons.help_outline_rounded, size: 12.w),
),
),
],
),
),
);
}
return Tab(text: _giftTabTitle(giftTab));
}
String _giftTabTitle(String giftTab) {
switch (giftTab) {
case "ALL":
return ATAppLocalizations.of(context)!.gift;
case "NATIONAL_FLAG":
return ATAppLocalizations.of(context)!.country;
case "ACTIVITY":
return ATAppLocalizations.of(context)!.activity;
case "LUCKY_GIFT":
return ATAppLocalizations.of(context)!.luck;
case "CP":
return ATAppLocalizations.of(context)!.cp;
case "CUSTOMIZED":
case "EXCLUSIVE":
return ATAppLocalizations.of(context)!.customized;
case "MAGIC":
return ATAppLocalizations.of(context)!.magic;
default:
return giftTab.replaceAll("_", " ");
}
}
void _selectGift(String giftTab, int checkedI) {
checkedGift = null;
final gifts =
Provider.of<AppGeneralManager>(
context,
listen: false,
).giftByTab[giftTab];
if (gifts != null && checkedI >= 0 && checkedI < gifts.length) {
final gift = gifts[checkedI];
if (gift.id != "-1000") {
checkedGift = gift;
}
}
number = 1;
noShowNumber = giftTab == ATGiftType.MAGIC.name;
setState(() {
giftType = _giftTypeValue(giftTab);
});
}
int _giftTypeValue(String giftTab) {
switch (giftTab) {
case "ACTIVITY":
return 1;
case "LUCKY_GIFT":
return 2;
case "CP":
return 3;
case "CUSTOMIZED":
case "EXCLUSIVE":
return 4;
case "MAGIC":
return 5;
default:
return 0;
}
}
void _showLuckyGiftHelpDialog() {
if (giftType != 2) {
return;
}
SmartDialog.show(
tag: "showLuckyGiftHelpDialog",
maskColor: Colors.black26,
alignment: Alignment.center,
animationType: SmartAnimationType.fade,
clickMaskDismiss: true,
builder: (_) {
return Material(
color: Colors.transparent,
child: Container(
width: ScreenUtil().screenWidth * 0.88,
padding: EdgeInsets.fromLTRB(15.w, 15.w, 15.w, 18.w),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20.w),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
Align(
alignment: Alignment.center,
child: text(
ATAppLocalizations.of(context)!.tips,
fontSize: 18.sp,
fontWeight: FontWeight.w700,
textColor: Color(0xFF303030),
),
),
Align(
alignment: Alignment.centerRight,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap:
() => SmartDialog.dismiss(
tag: "showLuckyGiftHelpDialog",
),
child: Container(
width: 28.w,
height: 28.w,
decoration: BoxDecoration(
border: Border.all(color: Colors.black, width: 2.w),
borderRadius: BorderRadius.circular(10.w),
),
child: Icon(
Icons.close,
size: 16.w,
color: Colors.black,
),
),
),
),
],
),
SizedBox(height: 22.w),
text(
ATAppLocalizations.of(context)!.luckGiftRuleTips,
maxLines: 20,
fontSize: 14.sp,
fontWeight: FontWeight.w600,
lineHeight: 1.45,
textColor: Color(0xFF404040),
),
],
),
),
);
},
);
}
void showGiveTypeDialog(BuildContext ct) {
SmartDialog.showAttach(
tag: "showGiveType",
targetContext: ct,
alignment: Alignment.bottomCenter,
animationType: SmartAnimationType.fade,
scalePointBuilder: (selfSize) => Offset(selfSize.width, 10),
builder: (_) {
return Container(
height: 135.w,
width: 200.w,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(_strategy.getGiftPageGiveTypeBackground()),
fit: BoxFit.fill,
),
),
padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 5.w),
child: Column(
children: [
SizedBox(height: 5.w),
Expanded(
child: GestureDetector(
child: Row(
children: [
Image.asset(
_strategy.getGiftPageAllOnMicrophoneIcon(),
height: 18.w,
width: 18.w,
),
SizedBox(width: 8.w),
Expanded(
child: text(
ATAppLocalizations.of(context)!.allOnMicrophone,
fontSize: 14.sp,
textColor: Colors.white54,
),
),
SizedBox(width: 8.w),
Image.asset(
giveType == 0
? _strategy.getCommonSelectIcon()
: _strategy.getCommonUnselectIcon(),
width: 15.w,
height: 15.w,
),
],
),
onTap: () {
giveType = 0;
SmartDialog.dismiss(tag: "showGiveType");
selecteAllMicUsers();
setState(() {});
},
),
),
Expanded(
child: GestureDetector(
child: Row(
children: [
Image.asset(
_strategy.getGiftPageUsersOnMicrophoneIcon(),
height: 18.w,
width: 18.w,
),
SizedBox(width: 8.w),
Expanded(
child: text(
ATAppLocalizations.of(context)!.usersOnMicrophone,
fontSize: 14.sp,
textColor: Colors.white54,
),
),
SizedBox(width: 8.w),
Image.asset(
giveType == 1
? _strategy.getCommonSelectIcon()
: _strategy.getCommonUnselectIcon(),
width: 15.w,
height: 15.w,
),
],
),
onTap: () {
giveType = 1;
SmartDialog.dismiss(tag: "showGiveType");
setState(() {});
},
),
),
Expanded(
child: GestureDetector(
onTap: () {
giveType = 2;
SmartDialog.dismiss(tag: "showGiveType");
setState(() {});
},
behavior: HitTestBehavior.opaque,
child: Row(
children: [
Image.asset(
_strategy.getGiftPageAllInTheRoomIcon(),
height: 18.w,
width: 18.w,
),
SizedBox(width: 8.w),
Expanded(
child: text(
ATAppLocalizations.of(context)!.allInTheRoom,
fontSize: 14.sp,
textColor: Colors.white54,
),
),
SizedBox(width: 8.w),
Image.asset(
giveType == 2
? _strategy.getCommonSelectIcon()
: _strategy.getCommonUnselectIcon(),
width: 15.w,
height: 15.w,
),
],
),
),
),
],
),
);
},
);
}
Widget _maiHead(HeadSelect shead) {
// 是否选中
return GestureDetector(
onTap: () {
isAll = true;
for (var mai in listMai) {
if (shead.mic?.user?.id == mai.mic?.user?.id) {
mai.isSelect = !mai.isSelect;
}
if (!mai.isSelect) {
isAll = false;
}
}
setState(() {});
},
child: Stack(
alignment: Alignment.bottomCenter,
clipBehavior: Clip.none,
children: <Widget>[
Stack(
alignment: AlignmentDirectional.center,
children: [
Container(
padding: EdgeInsets.all(2.w),
child: netImage(
url: shead.mic?.user?.userAvatar ?? "",
width: 26.w,
defaultImg: _strategy.getMePageDefaultAvatarImage(),
shape: BoxShape.circle,
),
),
PositionedDirectional(
bottom: 0,
end: 0,
child: Container(
alignment: AlignmentDirectional.center,
width: 12.w,
height: 12.w,
decoration: BoxDecoration(
color: Colors.black38,
shape: BoxShape.circle,
border:
shead.isSelect
? Border.all(
color: ChatVibeTheme.primaryLight,
width: 1.w,
)
: null,
),
child: text(
"${shead.mic?.micIndex}",
textColor: Colors.white,
fontSize: 8.sp,
),
),
),
shead.isSelect
? PositionedDirectional(
bottom: 0,
end: 0,
child: Image.asset(
"atu_images/login/at_icon_login_ser_select.png",
width: 12.w,
height: 12.w,
),
)
: Container(),
],
),
],
),
);
}
///数量选项
void _showNumber(BuildContext ct) {
SmartDialog.showAttach(
tag: "showNumber",
targetContext: ct,
maskColor: Colors.transparent,
alignment: Alignment.topLeft,
animationType: SmartAnimationType.fade,
scalePointBuilder: (selfSize) => Offset(selfSize.width, 10),
onDismiss: () {
isNumberUp = true;
setState(() {});
},
builder: (_) {
return Transform.translate(
offset: Offset(ATGlobalConfig.lang == "ar" ? 20 : -20, -5),
child: CheckNumber(
onNumberChanged: (number) {
this.number = number;
isNumberUp = true;
setState(() {});
},
),
);
},
);
}
///选中所有在座位上的用户
void selecteAllMicUsers() {
for (var mai in listMai) {
mai.isSelect = true;
}
}
///赠送礼物
void giveGifts() {
if (widget.isChatGift) {
if (checkedGift == null) {
return;
}
widget.onChatGiftSend?.call(checkedGift!, number);
return;
}
List<String> acceptUserIds = [];
List<MicRes> acceptUsers = [];
if (widget.toUser != null) {
acceptUserIds.add(widget.toUser?.id ?? "");
acceptUsers.add(MicRes(user: widget.toUser));
} else {
///所有在线
if (giveType == 2) {
for (var value
in Provider.of<RtcProvider>(context, listen: false).onlineUsers) {
acceptUsers.add(MicRes(user: value));
acceptUserIds.add(value.id ?? "");
}
} else {
for (var mu in listMai) {
if (mu.isSelect) {
acceptUsers.add(mu.mic!);
acceptUserIds.add(mu.mic!.user!.id ?? "");
}
}
}
}
if (acceptUserIds.isEmpty) {
ATTts.show(ATAppLocalizations.of(context)!.pleaseSelectTheRecipient);
return;
}
if (checkedGift == null) {
return;
}
if (checkedGift?.giftTab == ATGiftType.LUCKY_GIFT.name ||
checkedGift?.giftTab == ATGiftType.MAGIC.name) {
num price = checkedGift!.giftCandy! * number * acceptUserIds.length;
num myBalance =
Provider.of<ChatVibeUserProfileManager>(
context,
listen: false,
).myBalance;
if (price > myBalance) {
ATRoomUtils.goRechargeOperation(navigatorKey.currentContext!);
return;
}
SmartDialog.dismiss(tag: "showGiftControl");
SmartDialog.show(
tag: "showGiveRoomLuckPage",
alignment: Alignment.center,
maskColor: Colors.transparent,
clickMaskDismiss: false,
animationType: SmartAnimationType.fade,
builder: (_) {
return GiveRoomLuckPage(checkedGift!, acceptUserIds, () {
///幸运礼物
ChatRoomRepository()
.giveLuckyGift(
acceptUserIds,
checkedGift!.id ?? "",
number,
false,
roomId:
rtcProvider?.currenRoom?.roomProfile?.roomProfile?.id ??
"",
)
.then((result) {
// ATTts.show(ATAppLocalizations.of(context)!.giftGivingSuccessful);
sendGiftMsg(acceptUsers);
sendLuckGiftAnimOtherMsg(acceptUsers);
Provider.of<GiftProvider>(
navigatorKey.currentState!.context,
listen: false,
).updateLuckGiftNumber(
number * acceptUserIds.length,
acceptUserIds.length > 1,
acceptUsers.first,
checkedGift,
);
Provider.of<ChatVibeUserProfileManager>(
navigatorKey.currentState!.context,
listen: false,
).updateBalance(result);
})
.catchError((e) {});
});
},
onDismiss: () {
ATGiftVapSvgaManager().resumeAnim();
},
);
} else {
ChatRoomRepository()
.giveGift(
acceptUserIds,
checkedGift!.id ?? "",
number,
false,
roomId: rtcProvider?.currenRoom?.roomProfile?.roomProfile?.id ?? "",
)
.then((result) {
// ATTts.show(ATAppLocalizations.of(context)!.giftGivingSuccessful);
sendGiftMsg(acceptUsers);
Provider.of<ChatVibeUserProfileManager>(
context,
listen: false,
).updateBalance(result);
})
.catchError((e) {});
}
}
void sendGiftMsg(List<MicRes> acceptUsers) {
///发送一条IM消息
for (var u in acceptUsers) {
Provider.of<RtmProvider>(
navigatorKey.currentState!.context,
listen: false,
).sendMsg(
Msg(
groupId:
rtcProvider?.currenRoom?.roomProfile?.roomProfile?.roomAccount,
gift: checkedGift,
user: AccountStorage().getCurrentUser()?.userProfile,
toUser: u.user,
number: number,
type: ATRoomMsgType.gift,
role:
Provider.of<RtcProvider>(
navigatorKey.currentState!.context,
listen: false,
).currenRoom?.entrants?.roles ??
"",
msg: rtcProvider?.currenRoom?.roomProfile?.roomProfile?.id ?? "",
),
addLocal: true,
);
if (rtcProvider?.currenRoom?.roomProfile?.roomSetting?.showHeartbeat ??
false) {
debouncer.debounce(
duration: Duration(milliseconds: 350),
onDebounce: () {
Provider.of<RtcProvider>(
navigatorKey.currentState!.context,
listen: false,
).getMicList();
},
);
}
num coins = checkedGift!.giftCandy! * number;
if (coins > 9999) {
var fMsg = ATFloatingMessage(
type: 1,
userAvatarUrl:
AccountStorage().getCurrentUser()?.userProfile?.userAvatar ?? "",
userName:
AccountStorage().getCurrentUser()?.userProfile?.userNickname ??
"",
toUserName: u.user?.userNickname ?? "",
giftUrl: checkedGift?.giftPhoto ?? "",
roomId: rtcProvider?.currenRoom?.roomProfile?.roomProfile?.id ?? "",
coins: coins,
number: number,
);
OverlayManager().addMessage(fMsg);
}
if (checkedGift!.giftSourceUrl != null && checkedGift!.special != null) {
if (checkedGift!.special!.contains(ATGiftType.ANIMATION.name) ||
checkedGift!.special!.contains(ATGiftType.GLOBAL_GIFT.name)) {
if (ATGlobalConfig.isGiftSpecialEffects) {
ATGiftVapSvgaManager().play(checkedGift!.giftSourceUrl!);
}
}
}
}
}
/// 将数字giftType转换为字符串类型用于活动礼物头部背景
String _giftTypeToString(int giftType) {
switch (giftType) {
case 1: // ACTIVITY
return 'ACTIVITY';
case 2: // LUCKY_GIFT -> LUCK
return 'LUCK';
case 3: // CP
return 'CP';
case 5: // MAGIC
return 'MAGIC';
default:
return 'ACTIVITY';
}
}
_buildGiftHead() {
if (giftType == 1 || giftType == 5) {
// 获取基础路径
String basePath = _strategy.getGiftPageActivityGiftHeadBackground(
_giftTypeToString(giftType),
);
// 添加语言后缀
String imagePath;
if (ATGlobalConfig.lang == "ar") {
// 移除扩展名,添加 _ar 后缀,然后重新添加扩展名
if (basePath.endsWith('.png')) {
imagePath = basePath.substring(0, basePath.length - 4) + '_ar.png';
} else {
imagePath = basePath + '_ar';
}
} else {
if (basePath.endsWith('.png')) {
imagePath = basePath.substring(0, basePath.length - 4) + '_en.png';
} else {
imagePath = basePath + '_en';
}
}
// 确定高度
double height = giftType == 5 ? 80.w : 65.w;
return Container(
margin: EdgeInsets.symmetric(horizontal: 10.w),
child: Image.asset(imagePath, height: height, fit: BoxFit.fill),
);
}
return Container();
}
///发送一条消息,幸运礼物,房间里所有人都能看到礼物飘向麦位的动画
void sendLuckGiftAnimOtherMsg(List<MicRes> acceptUsers) {
Provider.of<RtmProvider>(
navigatorKey.currentState!.context,
listen: false,
).sendMsg(
Msg(
groupId: rtcProvider?.currenRoom?.roomProfile?.roomProfile?.roomAccount,
gift: checkedGift,
type: ATRoomMsgType.luckGiftAnimOther,
msg: jsonEncode(acceptUsers.map((u) => u.user?.id).toList()),
),
addLocal: false,
);
}
}
class CheckNumber extends StatelessWidget {
final Function(int) onNumberChanged;
late BuildContext context;
CheckNumber({super.key, required this.onNumberChanged});
@override
Widget build(BuildContext context) {
this.context = context;
return Container(
alignment: AlignmentDirectional.topEnd,
margin: EdgeInsets.only(right: width(22)),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(12.w)),
child: BackdropFilter(
filter: ui.ImageFilter.blur(sigmaX: 25, sigmaY: 25),
child: Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(Radius.circular(height(6))),
),
width: width(75),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(height: height(10)),
_item(1),
_item(7),
_item(17),
_item(77),
_item(777),
_item(7777),
SizedBox(height: height(10)),
],
),
),
),
),
);
}
_item(int number) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
SmartDialog.dismiss(tag: "showNumber");
onNumberChanged(number);
},
child: SizedBox(
height: height(24),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(width: width(10)),
Text(
"$number",
style: TextStyle(
fontSize: sp(14),
color: Colors.white,
fontWeight: FontWeight.w400,
decoration: TextDecoration.none,
),
),
SizedBox(width: width(10)),
],
),
),
);
}
}
class HeadSelect {
bool isSelect = false;
MicRes? mic;
HeadSelect(this.isSelect, this.mic);
}