| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:injectable/injectable.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/utils/atmob_log.dart';
- import '../../data/bean/character_group_info.dart';
- import '../../data/repository/characters_repository.dart';
- import '../../data/repository/keyboard_repository.dart';
- @injectable
- class CharacterController extends BaseController
- with GetTickerProviderStateMixin {
- final String tag = "CharacterController";
- final CharactersRepository charactersRepository;
- final ConfigRepository configRepository;
- final KeyboardRepository keyboardRepository;
- CharacterController(
- this.charactersRepository,
- this.configRepository,
- this.keyboardRepository,
- );
- // 人设主题
- RxList<CharacterGroupInfo> get characterGroupList =>
- charactersRepository.characterGroupList;
- // 键盘列表
- RxList<KeyboardInfo> get keyboardInfoList =>
- keyboardRepository.keyboardInfoList;
- late Rx<TabController> tabController;
- late PageController pageController;
- RxInt currentTabBarIndex = 0.obs;
- Rx<CharacterGroupInfo> currentCharacterGroupInfo = CharacterGroupInfo().obs;
- Rx<KeyboardInfo> currentKeyboardInfo = KeyboardInfo().obs;
- @override
- void onInit() {
- super.onInit();
- _dataLoad();
- }
- void _dataLoad() async {
- pageController = PageController();
- tabController =
- TabController(
- length: characterGroupList.length,
- vsync: this,
- initialIndex: 0,
- ).obs;
- ever(charactersRepository.characterGroupList, (value) {
- AtmobLog.d(tag, "characterGroupList changed");
- if (value.isNotEmpty) {
- tabController.value.dispose();
- tabController.value = TabController(
- length: characterGroupList.length,
- vsync: this,
- 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}");
- }
- });
- }
- void onTabChanged(int index) {
- if (index >= characterGroupList.length) {
- return;
- }
- pageController.animateToPage(
- index,
- duration: const Duration(milliseconds: 300),
- curve: Curves.easeInToLinear,
- );
- }
- void onPageChanged(int index) {
- if (index >= characterGroupList.length) {
- return;
- }
- currentTabBarIndex.value = index;
- currentCharacterGroupInfo.value = characterGroupList[index];
- tabController.value.animateTo(
- index,
- duration: const Duration(milliseconds: 300),
- );
- }
- @override
- void onReady() {
- super.onReady();
- }
- @override
- void onClose() {
- pageController.dispose();
- tabController.value.dispose();
- super.onClose();
- }
- clickMyKeyboard() {
- AtmobLog.d(tag, "clickMyKeyboard");
- }
- void updateSelectedValue(String? newValue) {
- currentKeyboardInfo.value = keyboardInfoList.firstWhere(
- (element) => element.name == newValue,
- orElse: () => keyboardInfoList.first,
- );
- }
- }
|