|
@@ -2,11 +2,13 @@ import 'package:flutter/material.dart';
|
|
|
import 'package:get/get.dart';
|
|
import 'package:get/get.dart';
|
|
|
import 'package:injectable/injectable.dart';
|
|
import 'package:injectable/injectable.dart';
|
|
|
import 'package:keyboard/base/base_controller.dart';
|
|
import 'package:keyboard/base/base_controller.dart';
|
|
|
|
|
+import 'package:keyboard/data/bean/keyboard_info.dart';
|
|
|
import 'package:keyboard/data/repository/config_repository.dart';
|
|
import 'package:keyboard/data/repository/config_repository.dart';
|
|
|
import 'package:keyboard/utils/atmob_log.dart';
|
|
import 'package:keyboard/utils/atmob_log.dart';
|
|
|
|
|
|
|
|
import '../../data/bean/character_group_info.dart';
|
|
import '../../data/bean/character_group_info.dart';
|
|
|
import '../../data/repository/characters_repository.dart';
|
|
import '../../data/repository/characters_repository.dart';
|
|
|
|
|
+import '../../data/repository/keyboard_repository.dart';
|
|
|
|
|
|
|
|
@injectable
|
|
@injectable
|
|
|
class CharacterController extends BaseController
|
|
class CharacterController extends BaseController
|
|
@@ -14,19 +16,30 @@ class CharacterController extends BaseController
|
|
|
final String tag = "CharacterController";
|
|
final String tag = "CharacterController";
|
|
|
final CharactersRepository charactersRepository;
|
|
final CharactersRepository charactersRepository;
|
|
|
final ConfigRepository configRepository;
|
|
final ConfigRepository configRepository;
|
|
|
|
|
+ final KeyboardRepository keyboardRepository;
|
|
|
|
|
|
|
|
- CharacterController(this.charactersRepository,this.configRepository);
|
|
|
|
|
|
|
+ CharacterController(
|
|
|
|
|
+ this.charactersRepository,
|
|
|
|
|
+ this.configRepository,
|
|
|
|
|
+ this.keyboardRepository,
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
|
|
+ // 人设主题
|
|
|
RxList<CharacterGroupInfo> get characterGroupList =>
|
|
RxList<CharacterGroupInfo> get characterGroupList =>
|
|
|
charactersRepository.characterGroupList;
|
|
charactersRepository.characterGroupList;
|
|
|
|
|
|
|
|
|
|
+ // 键盘列表
|
|
|
|
|
+ RxList<KeyboardInfo> get keyboardInfoList =>
|
|
|
|
|
+ keyboardRepository.keyboardInfoList;
|
|
|
|
|
+
|
|
|
late Rx<TabController> tabController;
|
|
late Rx<TabController> tabController;
|
|
|
late PageController pageController;
|
|
late PageController pageController;
|
|
|
|
|
+
|
|
|
RxInt currentTabBarIndex = 0.obs;
|
|
RxInt currentTabBarIndex = 0.obs;
|
|
|
|
|
|
|
|
- RxList<String> keyboardOptions = ["默认键盘", "新建键盘1"].obs;
|
|
|
|
|
|
|
+ Rx<CharacterGroupInfo> currentCharacterGroupInfo = CharacterGroupInfo().obs;
|
|
|
|
|
|
|
|
- Rx<String?> selectedValue = Rx<String?>(null);
|
|
|
|
|
|
|
+ Rx<KeyboardInfo> currentKeyboardInfo = KeyboardInfo().obs;
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
void onInit() {
|
|
void onInit() {
|
|
@@ -34,11 +47,9 @@ class CharacterController extends BaseController
|
|
|
_dataLoad();
|
|
_dataLoad();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
void _dataLoad() async {
|
|
void _dataLoad() async {
|
|
|
- charactersRepository.getCharactersGroup();
|
|
|
|
|
pageController = PageController();
|
|
pageController = PageController();
|
|
|
|
|
+
|
|
|
tabController =
|
|
tabController =
|
|
|
TabController(
|
|
TabController(
|
|
|
length: characterGroupList.length,
|
|
length: characterGroupList.length,
|
|
@@ -49,11 +60,25 @@ class CharacterController extends BaseController
|
|
|
ever(charactersRepository.characterGroupList, (value) {
|
|
ever(charactersRepository.characterGroupList, (value) {
|
|
|
AtmobLog.d(tag, "characterGroupList changed");
|
|
AtmobLog.d(tag, "characterGroupList changed");
|
|
|
if (value.isNotEmpty) {
|
|
if (value.isNotEmpty) {
|
|
|
|
|
+ tabController.value.dispose();
|
|
|
tabController.value = TabController(
|
|
tabController.value = TabController(
|
|
|
length: characterGroupList.length,
|
|
length: characterGroupList.length,
|
|
|
vsync: this,
|
|
vsync: this,
|
|
|
initialIndex: 0,
|
|
initialIndex: 0,
|
|
|
);
|
|
);
|
|
|
|
|
+ currentCharacterGroupInfo.value = characterGroupList.first;
|
|
|
|
|
+ AtmobLog.d(
|
|
|
|
|
+ tag,
|
|
|
|
|
+ "currentCharacterGroupInfo.value: ${characterGroupList.first.id}",
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ ever(keyboardRepository.keyboardInfoList, (value) {
|
|
|
|
|
+ AtmobLog.d(tag, "keyboardInfoList1 changed");
|
|
|
|
|
+ if (value.isNotEmpty) {
|
|
|
|
|
+ currentKeyboardInfo.value = keyboardInfoList.first;
|
|
|
|
|
+ print("currentKeyboardInfo.value: ${currentKeyboardInfo.value}");
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -62,7 +87,7 @@ class CharacterController extends BaseController
|
|
|
if (index >= characterGroupList.length) {
|
|
if (index >= characterGroupList.length) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- AtmobLog.d(tag, "onTabChanged index:$index");
|
|
|
|
|
|
|
+
|
|
|
pageController.animateToPage(
|
|
pageController.animateToPage(
|
|
|
index,
|
|
index,
|
|
|
duration: const Duration(milliseconds: 300),
|
|
duration: const Duration(milliseconds: 300),
|
|
@@ -71,12 +96,11 @@ class CharacterController extends BaseController
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void onPageChanged(int index) {
|
|
void onPageChanged(int index) {
|
|
|
-
|
|
|
|
|
if (index >= characterGroupList.length) {
|
|
if (index >= characterGroupList.length) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- AtmobLog.d(tag, "onPageChanged index:$index");
|
|
|
|
|
currentTabBarIndex.value = index;
|
|
currentTabBarIndex.value = index;
|
|
|
|
|
+ currentCharacterGroupInfo.value = characterGroupList[index];
|
|
|
tabController.value.animateTo(
|
|
tabController.value.animateTo(
|
|
|
index,
|
|
index,
|
|
|
duration: const Duration(milliseconds: 300),
|
|
duration: const Duration(milliseconds: 300),
|
|
@@ -99,22 +123,12 @@ class CharacterController extends BaseController
|
|
|
AtmobLog.d(tag, "clickMyKeyboard");
|
|
AtmobLog.d(tag, "clickMyKeyboard");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void updateSelectedValue(String? newValue) {
|
|
|
|
|
- selectedValue.value = newValue;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- // 添加一个新的键盘
|
|
|
|
|
- void addKeyboard(String name) {
|
|
|
|
|
- keyboardOptions.add(name);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- // 删除某个键盘
|
|
|
|
|
- void removeKeyboard(String name) {
|
|
|
|
|
- keyboardOptions.remove(name);
|
|
|
|
|
- // 如果删除的是当前选中的值,则重置
|
|
|
|
|
- if (selectedValue.value == name) {
|
|
|
|
|
- selectedValue.value =
|
|
|
|
|
- keyboardOptions.isNotEmpty ? keyboardOptions.first : null;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ void updateSelectedValue(String? newValue) {
|
|
|
|
|
+ currentKeyboardInfo.value = keyboardInfoList.firstWhere(
|
|
|
|
|
+ (element) => element.name == newValue,
|
|
|
|
|
+ orElse: () => keyboardInfoList.first,
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|