feat: 搜索直播间、用户

This commit is contained in:
guozhigq
2023-06-20 22:52:47 +08:00
parent 7e7892aab2
commit c2f8f143f8
15 changed files with 801 additions and 59 deletions

View File

@ -0,0 +1,48 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pilipala/http/search.dart';
import 'package:pilipala/models/common/search_type.dart';
class SearchPanelController extends GetxController {
SearchPanelController({this.keyword, this.searchType});
ScrollController scrollController = ScrollController();
String? keyword;
SearchType? searchType;
RxInt page = 1.obs;
RxList resultList = [].obs;
@override
void onInit() {
super.onInit();
}
Future onSearch({type = 'init'}) async {
var result = await SearchHttp.searchByType(
searchType: searchType!, keyword: keyword!, page: page.value);
if (result['status']) {
if (type == 'init') {
page.value++;
resultList.addAll(result['data'].list);
} else {
resultList.value = result['data'].list;
}
}
return result;
}
Future onRefresh() async {
page.value = 1;
onSearch(type: 'refresh');
}
// 返回顶部并刷新
void animateToTop() async {
if (scrollController.offset >=
MediaQuery.of(Get.context!).size.height * 5) {
scrollController.jumpTo(0);
} else {
await scrollController.animateTo(0,
duration: const Duration(milliseconds: 500), curve: Curves.easeInOut);
}
}
}