mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
64 lines
1.8 KiB
Dart
64 lines
1.8 KiB
Dart
import 'package:PiliPlus/models/common/live_search_type.dart';
|
|
import 'package:PiliPlus/pages/live_search/child/controller.dart';
|
|
import 'package:PiliPlus/utils/extension.dart';
|
|
import 'package:PiliPlus/utils/utils.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
class LiveSearchController extends GetxController
|
|
with GetSingleTickerProviderStateMixin {
|
|
late final tabController = TabController(vsync: this, length: 2);
|
|
final editingController = TextEditingController();
|
|
final focusNode = FocusNode();
|
|
|
|
final mid = Get.parameters['mid'];
|
|
final uname = Get.parameters['uname'];
|
|
|
|
final RxBool hasData = false.obs;
|
|
final RxList<int> counts = <int>[-1, -1].obs;
|
|
|
|
late final roomCtr = Get.put(
|
|
LiveSearchChildController(this, LiveSearchType.room),
|
|
tag: Utils.generateRandomString(8));
|
|
late final userCtr = Get.put(
|
|
LiveSearchChildController(this, LiveSearchType.user),
|
|
tag: Utils.generateRandomString(8));
|
|
|
|
void onClear() {
|
|
if (editingController.value.text.isNotEmpty) {
|
|
editingController.clear();
|
|
counts.value = <int>[-1, -1];
|
|
hasData.value = false;
|
|
focusNode.requestFocus();
|
|
} else {
|
|
Get.back();
|
|
}
|
|
}
|
|
|
|
late final regex = RegExp(r'^\d+$');
|
|
|
|
void submit() {
|
|
if (editingController.text.isNotEmpty) {
|
|
if (regex.hasMatch(editingController.text)) {
|
|
Get.toNamed('/liveRoom?roomid=${editingController.text}');
|
|
} else {
|
|
hasData.value = true;
|
|
roomCtr
|
|
..scrollController.jumpToTop()
|
|
..onReload();
|
|
userCtr
|
|
..scrollController.jumpToTop()
|
|
..onReload();
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
editingController.dispose();
|
|
focusNode.dispose();
|
|
tabController.dispose();
|
|
super.onClose();
|
|
}
|
|
}
|