mod: 历史页搜索逻辑修复、简化,横屏支持

This commit is contained in:
orz12
2024-03-08 05:28:39 +08:00
parent 83338da24c
commit 847140d98c
2 changed files with 33 additions and 95 deletions

View File

@@ -12,7 +12,6 @@ class HistorySearchController extends GetxController {
String hintText = '搜索';
RxString loadingStatus = 'init'.obs;
RxString loadingText = '加载中...'.obs;
bool hasRequest = false;
late int mid;
RxString uname = ''.obs;
int pn = 1;
@@ -37,11 +36,9 @@ class HistorySearchController extends GetxController {
// 提交搜索内容
void submit() {
loadingStatus.value = 'loading';
if (hasRequest) {
pn = 1;
searchHistories();
}
}
// 搜索视频
Future searchHistories({type = 'init'}) async {
@@ -58,18 +55,18 @@ class HistorySearchController extends GetxController {
} else {
historyList.addAll(res['data'].list);
}
historyList.refresh();
count = res['data'].page['total'];
if (historyList.length == count) {
loadingText.value = '没有更多了';
}
pn += 1;
hasRequest = true;
}
loadingStatus.value = 'finish';
return res;
// return res;
}
onLoad() {
pn += 1;
searchHistories(type: 'onLoad');
}

View File

@@ -6,6 +6,8 @@ import 'package:PiliPalaX/common/widgets/http_error.dart';
import 'package:PiliPalaX/common/widgets/no_data.dart';
import 'package:PiliPalaX/pages/history/widgets/item.dart';
import '../../common/constants.dart';
import '../../utils/grid.dart';
import 'controller.dart';
class HistorySearchPage extends StatefulWidget {
@@ -80,93 +82,32 @@ class _HistorySearchPageState extends State<HistorySearchPage> {
),
),
body: Obx(
() => Column(
children: _historySearchCtr.loadingStatus.value == 'init'
? [const SizedBox()]
: [
Expanded(
child: FutureBuilder(
future: _historySearchCtr.searchHistories(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
Map data = snapshot.data as Map;
if (data['status']) {
return Obx(
() => _historySearchCtr.historyList.isNotEmpty
? ListView.builder(
() => _historySearchCtr.loadingStatus.value == 'init'
? const SizedBox()
: CustomScrollView(
physics: const AlwaysScrollableScrollPhysics(),
controller: scrollController,
itemCount:
_historySearchCtr.historyList.length +
1,
itemBuilder: (context, index) {
if (index ==
_historySearchCtr
.historyList.length) {
return Container(
height: MediaQuery.of(context)
.padding
.bottom +
60,
padding: EdgeInsets.only(
bottom: MediaQuery.of(context)
.padding
.bottom),
child: Center(
child: Obx(
() => Text(
_historySearchCtr
.loadingText.value,
style: TextStyle(
color: Theme.of(context)
.colorScheme
.outline,
fontSize: 13),
),
),
),
);
} else {
slivers: [
Obx(() => SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
mainAxisSpacing: StyleString.cardSpace,
crossAxisSpacing: StyleString.safeSpace,
maxCrossAxisExtent: Grid.maxRowWidth * 2,
mainAxisExtent: Grid.calculateActualWidth(context,
Grid.maxRowWidth * 2, StyleString.safeSpace) /
2.1 /
StyleString.aspectRatio),
delegate: SliverChildBuilderDelegate(
(context, index) {
return HistoryItem(
videoItem: _historySearchCtr
.historyList[index],
videoItem: _historySearchCtr.historyList[index],
ctr: _historySearchCtr,
onChoose: null,
onUpdateMultiple: () => null,
);
}
},
)
: _historySearchCtr.loadingStatus.value ==
'loading'
? const SizedBox(child: Text('加载中...'))
: const CustomScrollView(
slivers: <Widget>[
NoData(),
],
),
);
} else {
return CustomScrollView(
slivers: <Widget>[
HttpError(
errMsg: data['msg'],
fn: () => setState(() {}),
)
],
);
}
} else {
// 骨架屏
return ListView.builder(
itemCount: 10,
itemBuilder: (context, index) {
return const VideoCardHSkeleton();
},
);
}
},
),
),
childCount: _historySearchCtr.historyList.length,
)))
],
),
),