Browse Source

add: choose 3 topics

pull/18/head
AmirrezaChegini 2 weeks ago
parent
commit
b3069e0553
  1. 17
      lib/features/battle_league/first_part/presentation/controller/battle_league_controller.dart
  2. 11
      lib/features/battle_league/first_part/presentation/ui/battle_league_topic_page.dart
  3. 16
      lib/features/battle_league/first_part/presentation/ui/widgets/topic_page/topic_widget.dart

17
lib/features/battle_league/first_part/presentation/controller/battle_league_controller.dart

@ -29,6 +29,7 @@ class BattleLeagueController extends GetxController
/// ----- Variables ----- /// ----- Variables -----
final BattleLeagueParams battleLeagueParams = BattleLeagueParams(); final BattleLeagueParams battleLeagueParams = BattleLeagueParams();
final RxList<TopicsEntity> topicList = RxList.empty(); final RxList<TopicsEntity> topicList = RxList.empty();
final RxList<TopicsEntity> chooseTopicList = RxList.empty();
/// ------ Controllers ------ /// ------ Controllers ------
final TextEditingController textEditingController = TextEditingController(); final TextEditingController textEditingController = TextEditingController();
@ -52,6 +53,22 @@ class BattleLeagueController extends GetxController
Get.toNamed(Routes.battleLeagueFoundedPage); 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<TopicsEntity> newTopicList = List.from(topicList);
newTopicList.shuffle();
chooseTopicList.value = newTopicList.take(3).toList();
}
/// ------ Api Calls ------ /// ------ Api Calls ------
Future<void> getTopics() async { Future<void> getTopics() async {
getTopicsStatus.value = const BaseLoading(); getTopicsStatus.value = const BaseLoading();

11
lib/features/battle_league/first_part/presentation/ui/battle_league_topic_page.dart

@ -97,9 +97,12 @@ class BattleLeagueTopicPage extends GetView<BattleLeagueController> {
alignment: WrapAlignment.center, alignment: WrapAlignment.center,
children: List.generate( children: List.generate(
controller.topicList.length, 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<BattleLeagueController> {
child: BattleGreyButton( child: BattleGreyButton(
label: context.translate.random, label: context.translate.random,
image: MyAssets.iconRandom, image: MyAssets.iconRandom,
onTap: () {},
onTap: controller.choosRandomTopic,
), ),
); );
} }

16
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: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/common_ui/resources/my_text_style.dart';
import 'package:shia_game_flutter/core/utils/screen_size.dart'; import 'package:shia_game_flutter/core/utils/screen_size.dart';
import 'package:shia_game_flutter/core/widgets/container/my_container.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 { class TopicWidget extends StatelessWidget {
const TopicWidget({ const TopicWidget({
super.key, super.key,
this.onTap,
required this.topic, required this.topic,
this.onPressed,
this.selected = false,
}); });
final VoidCallback? onTap;
final void Function(TopicsEntity topic)? onPressed;
final TopicsEntity topic; final TopicsEntity topic;
final bool selected;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MyContainer( return MyContainer(
onTap: onTap,
onTap: () {
onPressed?.call(topic);
},
height: 48.h, height: 48.h,
width: 148.w, width: 148.w,
borderRadius: const BorderRadius.all(Radius.circular(12)), borderRadius: const BorderRadius.all(Radius.circular(12)),
borderGradient: LinearGradient(
borderGradient: !selected ? null : LinearGradient(
begin: AlignmentDirectional.centerStart, begin: AlignmentDirectional.centerStart,
end: AlignmentDirectional.centerEnd, end: AlignmentDirectional.centerEnd,
colors: [ colors: [
@ -30,7 +35,7 @@ class TopicWidget extends StatelessWidget {
const Color(0XFFAA76FF).withValues(alpha: 0), const Color(0XFFAA76FF).withValues(alpha: 0),
], ],
), ),
gradient: const RadialGradient(
gradient: !selected ? null : const RadialGradient(
center: Alignment.center, center: Alignment.center,
radius: 3, radius: 3,
colors: [ colors: [
@ -38,6 +43,7 @@ class TopicWidget extends StatelessWidget {
Color(0XFF792BF3), Color(0XFF792BF3),
], ],
), ),
color: selected ? null : MyColors.black.withValues(alpha: 0.2),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
offset: const Offset(0, 3.53), offset: const Offset(0, 3.53),

Loading…
Cancel
Save