2026-07-01 18:25:58 +08:00

1186 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/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.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_core/utilities/at_dialog_utils.dart';
import 'package:aslan/chatvibe_core/utilities/at_lk_dialog_util.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/countdown_timer.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/activity/gift_tab_activity_page.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;
GiftPage({super.key, this.toUser, this.initialIndex = 0});
@override
_GiftPageState createState() => _GiftPageState();
}
class _GiftPageState extends State<GiftPage>
with SingleTickerProviderStateMixin {
late TabController _tabController;
/// 业务逻辑策略访问器
BusinessLogicStrategy get _strategy => ATGlobalConfig.businessLogicStrategy;
// int checkedIndex = 0;
ChatVibeGiftRes? checkedGift;
final List<Widget> _pages = [];
final List<Widget> _tabs = [];
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();
_pages.add(
GiftTabPage("ALL", (int checkedI) {
checkedGift = null;
var all =
Provider.of<AppGeneralManager>(
context,
listen: false,
).giftByTab["ALL"];
if (all != null) {
checkedGift = all[checkedI];
}
number = 1;
noShowNumber = false;
setState(() {
giftType = 0;
});
}),
);
// _pages.add(
// GiftTabPage("NATIONAL_FLAG", (int checkedI) {
// checkedGift = null;
// var flag =
// Provider.of<AppGeneralManager>(
// context,
// listen: false,
// ).giftByTab["NATIONAL_FLAG"];
// if (flag != null) {
// checkedGift = flag[checkedI];
// }
// number = 1;
// noShowNumber = false;
// setState(() {
// giftType = 0;
// });
// }),
// );
// _pages.add(
// GiftTabActivityPage("ACTIVITY", (int checkedI, String activityId) {
// checkedGift = null;
// var exclusive =
// Provider.of<AppGeneralManager>(
// context,
// listen: false,
// ).activityGiftByTab[activityId];
// if (exclusive != null) {
// checkedGift = exclusive[checkedI];
// }
// number = 1;
// noShowNumber = false;
// setState(() {
// giftType = 1;
// });
// }),
// );
_pages.add(
GiftTabPage("LUCKY_GIFT", (int checkedI) {
checkedGift = null;
var exclusive =
Provider.of<AppGeneralManager>(
context,
listen: false,
).giftByTab["LUCKY_GIFT"];
if (exclusive != null) {
checkedGift = exclusive[checkedI];
}
number = 1;
noShowNumber = false;
setState(() {
giftType = 2;
});
}),
);
_pages.add(
GiftTabPage("CP", (int checkedI) {
checkedGift = null;
var exclusive =
Provider.of<AppGeneralManager>(
context,
listen: false,
).giftByTab["CP"];
if (exclusive != null) {
checkedGift = exclusive[checkedI];
}
number = 1;
noShowNumber = false;
setState(() {
giftType = 3;
});
}),
);
// _pages.add(
// GiftTabPage("CUSTOMIZED", (int checkedI) {
// checkedGift = null;
// var exclusive =
// Provider.of<AppGeneralManager>(
// context,
// listen: false,
// ).giftByTab["CUSTOMIZED"];
//
// if (exclusive != null && exclusive.length > 1) {
// checkedGift = exclusive[checkedI];
// }
// number = 1;
// noShowNumber = false;
// setState(() {
// giftType = 4;
// });
// }),
// );
// _pages.add(
// GiftTabPage("MAGIC", (int checkedI) {
// checkedGift = null;
// var exclusive =
// Provider.of<AppGeneralManager>(
// context,
// listen: false,
// ).giftByTab["MAGIC"];
// if (exclusive != null) {
// checkedGift = exclusive[checkedI];
// }
// number = 1;
// noShowNumber = true;
// setState(() {
// giftType = 5;
// });
// }),
// );
_tabController = TabController(
length: _pages.length,
vsync: this,
initialIndex: widget.initialIndex,
);
_tabController.addListener(() {}); // 监听切换
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
Widget build(BuildContext context) {
_tabs.clear();
_tabs.add(Tab(text: ATAppLocalizations.of(context)!.gift));
// _tabs.add(Tab(text: ATAppLocalizations.of(context)!.country));
// _tabs.add(Tab(text: ATAppLocalizations.of(context)!.activity));
_tabs.add(
Tab(
child: Directionality(textDirection: TextDirection.ltr, child: Stack(
clipBehavior: Clip.none,
children: [
Padding(
padding: EdgeInsets.only(right: 10.w),
child: Text(ATAppLocalizations.of(context)!.luck),
),
Positioned(
top: -6.w,
right: -3.w,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: _showLuckyGiftHelpDialog,
child: Icon(Icons.help_outline_rounded, size: 12.w),
),
),
],
)),
),
);
_tabs.add(Tab(text: ATAppLocalizations.of(context)!.cp));
// _tabs.add(Tab(text: ATAppLocalizations.of(context)!.customized));
// _tabs.add(Tab(text: ATAppLocalizations.of(context)!.magic));
return Consumer<AppGeneralManager>(
builder: (context, ref, child) {
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),
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: 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: 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),
],
),
),
),
],
),
);
},
);
}
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() {
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);
}