From b3069e0553980c80ea0bd00453fb4406a4fef9cf Mon Sep 17 00:00:00 2001 From: AmirrezaChegini Date: Sun, 23 Nov 2025 10:51:17 +0330 Subject: [PATCH] add: choose 3 topics --- .../controller/battle_league_controller.dart | 17 +++++++++++++++++ .../ui/battle_league_topic_page.dart | 11 +++++++---- .../ui/widgets/topic_page/topic_widget.dart | 16 +++++++++++----- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/lib/features/battle_league/first_part/presentation/controller/battle_league_controller.dart b/lib/features/battle_league/first_part/presentation/controller/battle_league_controller.dart index b949ff1..1de8cf8 100644 --- a/lib/features/battle_league/first_part/presentation/controller/battle_league_controller.dart +++ b/lib/features/battle_league/first_part/presentation/controller/battle_league_controller.dart @@ -29,6 +29,7 @@ class BattleLeagueController extends GetxController /// ----- Variables ----- final BattleLeagueParams battleLeagueParams = BattleLeagueParams(); final RxList topicList = RxList.empty(); + final RxList chooseTopicList = RxList.empty(); /// ------ Controllers ------ final TextEditingController textEditingController = TextEditingController(); @@ -52,6 +53,22 @@ class BattleLeagueController extends GetxController Get.toNamed(Routes.battleLeagueFoundedPage); } + void chooseTopic(TopicsEntity topic) { + if (chooseTopicList.contains(topic)) { + chooseTopicList.remove(topic); + } else { + if (chooseTopicList.length < 3) { + chooseTopicList.add(topic); + } + } + } + + void choosRandomTopic() { + final List newTopicList = List.from(topicList); + newTopicList.shuffle(); + chooseTopicList.value = newTopicList.take(3).toList(); + } + /// ------ Api Calls ------ Future getTopics() async { getTopicsStatus.value = const BaseLoading(); diff --git a/lib/features/battle_league/first_part/presentation/ui/battle_league_topic_page.dart b/lib/features/battle_league/first_part/presentation/ui/battle_league_topic_page.dart index f4d208b..bad3f90 100644 --- a/lib/features/battle_league/first_part/presentation/ui/battle_league_topic_page.dart +++ b/lib/features/battle_league/first_part/presentation/ui/battle_league_topic_page.dart @@ -97,9 +97,12 @@ class BattleLeagueTopicPage extends GetView { alignment: WrapAlignment.center, children: List.generate( controller.topicList.length, - (index) => TopicWidget( - topic: controller.topicList[index], - onTap: () {}, + (index) => Obx( + () => TopicWidget( + onPressed: controller.chooseTopic, + topic: controller.topicList[index], + selected: controller.chooseTopicList.contains(controller.topicList[index]), + ), ), ), ), @@ -113,7 +116,7 @@ class BattleLeagueTopicPage extends GetView { child: BattleGreyButton( label: context.translate.random, image: MyAssets.iconRandom, - onTap: () {}, + onTap: controller.choosRandomTopic, ), ); } diff --git a/lib/features/battle_league/first_part/presentation/ui/widgets/topic_page/topic_widget.dart b/lib/features/battle_league/first_part/presentation/ui/widgets/topic_page/topic_widget.dart index 80e50d5..3f55557 100644 --- a/lib/features/battle_league/first_part/presentation/ui/widgets/topic_page/topic_widget.dart +++ b/lib/features/battle_league/first_part/presentation/ui/widgets/topic_page/topic_widget.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:shia_game_flutter/common_ui/resources/my_colors.dart'; import 'package:shia_game_flutter/common_ui/resources/my_text_style.dart'; import 'package:shia_game_flutter/core/utils/screen_size.dart'; import 'package:shia_game_flutter/core/widgets/container/my_container.dart'; @@ -8,21 +9,25 @@ import 'package:shia_game_flutter/features/battle_league/first_part/domain/entit class TopicWidget extends StatelessWidget { const TopicWidget({ super.key, - this.onTap, required this.topic, + this.onPressed, + this.selected = false, }); - final VoidCallback? onTap; + final void Function(TopicsEntity topic)? onPressed; final TopicsEntity topic; + final bool selected; @override Widget build(BuildContext context) { return MyContainer( - onTap: onTap, + onTap: () { + onPressed?.call(topic); + }, height: 48.h, width: 148.w, borderRadius: const BorderRadius.all(Radius.circular(12)), - borderGradient: LinearGradient( + borderGradient: !selected ? null : LinearGradient( begin: AlignmentDirectional.centerStart, end: AlignmentDirectional.centerEnd, colors: [ @@ -30,7 +35,7 @@ class TopicWidget extends StatelessWidget { const Color(0XFFAA76FF).withValues(alpha: 0), ], ), - gradient: const RadialGradient( + gradient: !selected ? null : const RadialGradient( center: Alignment.center, radius: 3, colors: [ @@ -38,6 +43,7 @@ class TopicWidget extends StatelessWidget { Color(0XFF792BF3), ], ), + color: selected ? null : MyColors.black.withValues(alpha: 0.2), boxShadow: [ BoxShadow( offset: const Offset(0, 3.53),