mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-20 00:56:31 +08:00
feat: live search
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
63
lib/pages/live_search/controller.dart
Normal file
63
lib/pages/live_search/controller.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user