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:aslan/app_localizations.dart'; import 'package:aslan/chatvibe_ui/components/text/at_text.dart'; import 'package:aslan/chatvibe_domain/models/res/at_room_reward_info_res.dart'; import 'package:aslan/chatvibe_features/room/rank/room_reward_rule_page.dart'; import 'package:provider/provider.dart'; import 'package:aslan/chatvibe_data/sources/repositories/room_repository_imp.dart'; import 'package:aslan/chatvibe_managers/rtc_manager.dart'; import 'package:aslan/chatvibe_ui/widgets/room/redpack/room_redenvelope_config_page.dart'; import 'package:aslan/chatvibe_ui/widgets/room_reward_countdown_timer.dart'; class RoomRewardPage extends StatefulWidget { @override _RoomRewardPageState createState() => _RoomRewardPageState(); } class _RoomRewardPageState extends State { String roomId = ""; ATRoomRewardInfoRes? res; @override void initState() { super.initState(); roomId = Provider.of( context, listen: false, ).currenRoom?.roomProfile?.roomProfile?.id ?? ""; loadRoomRewardInfo(); } @override Widget build(BuildContext context) { return SafeArea( child: Container( height: Provider.of(context, listen: false).isFz() && (res?.lastWeekProgress?.amount ?? 0) > 0 ? ScreenUtil().screenHeight * 0.85 : ScreenUtil().screenHeight * 0.65, width: ScreenUtil().screenWidth, decoration: BoxDecoration( image: DecorationImage( image: AssetImage("atu_images/room/at_icon_room_reward_bg.png"), fit: BoxFit.fill, ), ), child: Column( children: [ SizedBox(height: 40.w), Image.asset( "atu_images/room/at_icon_room_reward_title.png", height: 100.w, ), Expanded( child: SingleChildScrollView( child: Column( children: [ Row( children: [ Spacer(), GestureDetector( child: Image.asset( "atu_images/room/at_icon_room_reward_help.png", width: 20.w, ), onTap: () { SmartDialog.show( tag: "showRoomRewardRulePage", alignment: Alignment.bottomCenter, animationType: SmartAnimationType.fade, builder: (_) { return RoomRewardRulePage(); }, ); }, ), SizedBox(width: 25.w), ], ), SizedBox(height: 5.w), Directionality( textDirection: TextDirection.ltr, child: RoomRewardCountdownTimer( key: UniqueKey(), targetDate: DateTime.fromMillisecondsSinceEpoch( res?.countdown ?? 0, ), ), ), SizedBox(height: 5.w), Container( height: 210.w, width: ScreenUtil().screenWidth, margin: EdgeInsets.symmetric(horizontal: 15.w), decoration: BoxDecoration( image: DecorationImage( image: AssetImage( "atu_images/room/at_icon_room_reward_content_bg.png", ), fit: BoxFit.fill, ), ), child: Column( mainAxisSize: MainAxisSize.min, children: [ SizedBox(height: 52.w), text( ATAppLocalizations.of(context)!.currentProgress, fontSize: 15.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ), SizedBox(height: 35.w), Row( children: [ SizedBox(width: 25.w), text( ATAppLocalizations.of(context)!.currentStage( "${res?.currentProgress?.amount ?? 0}", ), fontSize: 13.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ), ], ), SizedBox(height: 15.w), Row( children: [ SizedBox(width: 25.w), text( ATAppLocalizations.of(context)!.roomReward2( "Lv.${res?.currentProgress?.level ?? 0}", ), fontSize: 15.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ), ], ), ], ), ), SizedBox(height: 5.w), Provider.of(context, listen: false).isFz() && (res?.lastWeekProgress?.amount ?? 0) > 0 ? Container( height: 210.w, width: ScreenUtil().screenWidth, margin: EdgeInsets.symmetric(horizontal: 15.w), decoration: BoxDecoration( image: DecorationImage( image: AssetImage( "atu_images/room/at_icon_room_reward_content_bg.png", ), fit: BoxFit.fill, ), ), child: Column( mainAxisSize: MainAxisSize.min, children: [ SizedBox(height: 52.w), text( ATAppLocalizations.of(context)!.lastWeekProgress, fontSize: 15.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ), SizedBox(height: 22.w), Row( children: [ SizedBox(width: 25.w), text( ATAppLocalizations.of(context)!.roomReward2( "${res?.lastWeekProgress?.amount ?? 0}(Lv.${res?.lastWeekProgress?.level ?? 0})", ), fontSize: 13.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ), ], ), SizedBox(height: 3.w), Row( children: [ SizedBox(width: 25.w), text( ATAppLocalizations.of( context, )!.ownerIncomeCoins( "${res?.lastWeekProgress?.ownerIncome ?? 0}", ), fontSize: 13.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ), Spacer(), GestureDetector( child: Container( width: 90.w, height: 30.w, alignment: Alignment.center, decoration: BoxDecoration( image: DecorationImage( image: AssetImage( (res ?.lastWeekProgress ?.ownerIncomeReceived ?? false) ? "atu_images/room/at_icon_room_reward_btn_no.png" : "atu_images/room/at_icon_room_reward_btn_en.png", ), ), ), child: text( (res ?.lastWeekProgress ?.ownerIncomeReceived ?? false) ? ATAppLocalizations.of( context, )!.received : ATAppLocalizations.of( context, )!.receive, fontSize: 10.sp, ), ), onTap: () { roomRewardReceive(); }, ), SizedBox(width: 25.w), ], ), (res?.lastWeekProgress?.rewardCoins ?? 0) > 0 ? Transform.translate( offset: Offset(0, 0), child: Row( children: [ SizedBox(width: 25.w), text( ATAppLocalizations.of( context, )!.rewardCoins( "${res?.lastWeekProgress?.rewardCoins ?? 0}", ), fontSize: 13.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ), Spacer(), GestureDetector( child: Container( width: 90.w, height: 30.w, alignment: Alignment.center, decoration: BoxDecoration( image: DecorationImage( image: AssetImage( (res ?.lastWeekProgress ?.rewardCoinsSent ?? false) ? "atu_images/room/at_icon_room_reward_btn_no.png" : "atu_images/room/at_icon_room_reward_btn_en.png", ), ), ), child: text( (res ?.lastWeekProgress ?.rewardCoinsSent ?? false) ? ATAppLocalizations.of( context, )!.sent : ATAppLocalizations.of( context, )!.send, fontSize: 10.sp, ), ), onTap: () { if ((res ?.lastWeekProgress ?.rewardCoinsSent ?? false)) { return; } SmartDialog.show( tag: "showRedEnvelopeConfig", alignment: Alignment.center, animationType: SmartAnimationType.fade, builder: (_) { return RoomRedenvelopeConfigPage( 2, rewardCoins: res ?.lastWeekProgress ?.rewardCoins ?? 0, ); }, onDismiss: (){ loadRoomRewardInfo(); } ); }, ), SizedBox(width: 25.w), ], ), ) : Container(), ], ), ) : Container(), SizedBox(height: 10.w), ], ), ), ), ], ), ), ); } void roomRewardReceive() async { try { if ((res?.lastWeekProgress?.ownerIncomeReceived ?? false)) { return; } await ChatRoomRepository().roomRewardReceive(roomId); loadRoomRewardInfo(); } catch (e) {} } void loadRoomRewardInfo() { ChatRoomRepository() .roomRewardInfo(roomId) .then((result) { res = result; setState(() {}); }) .catchError((e) {}); } }