mod: 搜索页面完善
This commit is contained in:
@ -11,19 +11,14 @@ class SearchPanelController extends GetxController {
|
||||
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') {
|
||||
if (type == 'init' || type == 'onLoad') {
|
||||
page.value++;
|
||||
resultList.addAll(result['data'].list);
|
||||
} else {
|
||||
} else if (type == 'onRefresh') {
|
||||
resultList.value = result['data'].list;
|
||||
}
|
||||
}
|
||||
@ -32,7 +27,7 @@ class SearchPanelController extends GetxController {
|
||||
|
||||
Future onRefresh() async {
|
||||
page.value = 1;
|
||||
onSearch(type: 'refresh');
|
||||
onSearch(type: 'onRefresh');
|
||||
}
|
||||
|
||||
// 返回顶部并刷新
|
||||
|
||||
@ -23,6 +23,8 @@ class _SearchPanelState extends State<SearchPanel>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
late SearchPanelController? _searchPanelController;
|
||||
|
||||
bool _isLoadingMore = false;
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@ -30,11 +32,24 @@ class _SearchPanelState extends State<SearchPanel>
|
||||
void initState() {
|
||||
super.initState();
|
||||
_searchPanelController = Get.put(
|
||||
SearchPanelController(
|
||||
keyword: widget.keyword,
|
||||
searchType: widget.searchType,
|
||||
),
|
||||
tag: widget.searchType!.type);
|
||||
SearchPanelController(
|
||||
keyword: widget.keyword,
|
||||
searchType: widget.searchType,
|
||||
),
|
||||
tag: widget.searchType!.type,
|
||||
);
|
||||
ScrollController scrollController =
|
||||
_searchPanelController!.scrollController;
|
||||
scrollController.addListener(() async {
|
||||
if (scrollController.position.pixels >=
|
||||
scrollController.position.maxScrollExtent - 100) {
|
||||
if (!_isLoadingMore) {
|
||||
_isLoadingMore = true;
|
||||
await _searchPanelController!.onSearch(type: 'onLoad');
|
||||
_isLoadingMore = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@ -71,9 +86,14 @@ class _SearchPanelState extends State<SearchPanel>
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return HttpError(
|
||||
errMsg: data['msg'],
|
||||
fn: () => setState(() {}),
|
||||
return CustomScrollView(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
HttpError(
|
||||
errMsg: data['msg'],
|
||||
fn: () => setState(() {}),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user