| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import '../../../constants/iconfont/iconfont.dart';
- import '../../../data/models/launch/groups.dart';
- import '../../../data/sp/ix_sp.dart';
- class NodeController extends GetxController {
- // Groups 数据
- final _groups = Rxn<Groups>();
- Groups? get groups => _groups.value;
- set groups(Groups? value) => _groups.value = value;
- // 游戏tab列表
- final _tabTextList = <String>[].obs;
- List<String> get tabTextList => _tabTextList;
- set tabTextList(List<String> value) => _tabTextList.assignAll(value);
- // 当前选中的 Tab 索引
- final _currentTabIndex = 0.obs;
- int get currentTabIndex => _currentTabIndex.value;
- set currentTabIndex(int value) => _currentTabIndex.value = value;
- // 保存每个 tab 中每个国家的展开/收缩状态
- // key 格式: "tabIndex_countryCode"
- final Map<String, bool> expandedStates = {};
- @override
- void onInit() {
- super.onInit();
- _loadGroups();
- }
- /// 加载 Groups 数据
- void _loadGroups() {
- final launch = IXSP.getLaunch();
- if (launch?.groups != null) {
- groups = launch!.groups;
- _updateTabList();
- }
- }
- void updateGroups(Groups? groups) {
- this.groups = groups;
- _updateTabList();
- }
- /// 更新 Tab 列表
- void _updateTabList() {
- final tabs = <String>[];
- // 添加 Normal tab
- if (groups?.normal != null && groups!.normal!.list?.isNotEmpty == true) {
- tabs.add('All');
- }
- // 添加 Streaming tab
- if (groups?.streaming != null &&
- groups!.streaming!.list?.isNotEmpty == true) {
- tabs.add('Streaming');
- }
- tabTextList = tabs;
- }
- /// 根据 tab 索引获取对应的数据
- Normal? getDataByTabIndex(int tabIndex) {
- if (tabIndex == 0) {
- return groups?.normal;
- } else if (tabIndex == 1) {
- return groups?.streaming;
- }
- return null;
- }
- IconData getTabIcon(int tabIndex) {
- if (tabIndex == 0) {
- return IconFont.icon24;
- } else if (tabIndex == 1) {
- return IconFont.icon25;
- }
- return IconFont.icon24;
- }
- /// 获取国家的展开状态
- bool getExpandedState(int tabIndex, String countryCode) {
- final key = '${tabIndex}_$countryCode';
- return expandedStates[key] ?? false; // 默认收缩
- }
- /// 设置国家的展开状态
- void setExpandedState(int tabIndex, String countryCode, bool expanded) {
- final key = '${tabIndex}_$countryCode';
- expandedStates[key] = expanded;
- }
- }
|