feat: 视频搜索时长筛选v2

This commit is contained in:
guozhigq
2023-08-22 11:47:19 +08:00
parent 8703d9f576
commit 9e44995082
3 changed files with 107 additions and 34 deletions

View File

@ -47,17 +47,17 @@ class SearchHttp {
required String keyword, required String keyword,
required page, required page,
String? order, String? order,
int? duration,
}) async { }) async {
Map<String, dynamic> reqData = { var reqData = {
'search_type': searchType.type, 'search_type': searchType.type,
'keyword': keyword, 'keyword': keyword,
// 'order_sort': 0, // 'order_sort': 0,
// 'user_type': 0, // 'user_type': 0,
'page': page, 'page': page,
if (order != null) 'order': order,
if (duration != null) 'duration': duration,
}; };
if (order != null && order != '') {
reqData['order'] = order;
}
var res = await Request().get(Api.searchByType, data: reqData); var res = await Request().get(Api.searchByType, data: reqData);
if (res.data['code'] == 0 && res.data['data']['numPages'] > 0) { if (res.data['code'] == 0 && res.data['data']['numPages'] > 0) {
Object data; Object data;

View File

@ -12,15 +12,18 @@ class SearchPanelController extends GetxController {
SearchType? searchType; SearchType? searchType;
RxInt page = 1.obs; RxInt page = 1.obs;
RxList resultList = [].obs; RxList resultList = [].obs;
// 结果排序方式 搜索类型为视频、专栏及相簿时
RxString order = ''.obs; RxString order = ''.obs;
// 视频时长筛选 仅用于搜索视频
RxInt duration = 0.obs;
Future onSearch({type = 'init'}) async { Future onSearch({type = 'init'}) async {
var result = await SearchHttp.searchByType( var result = await SearchHttp.searchByType(
searchType: searchType!, searchType: searchType!,
keyword: keyword!, keyword: keyword!,
page: page.value, page: page.value,
order: searchType!.type != 'video' ? '' : order.value, order: searchType!.type != 'video' ? null : order.value,
); duration: searchType!.type != 'video' ? null : duration.value);
if (result['status']) { if (result['status']) {
if (type == 'onRefresh') { if (type == 'onRefresh') {
resultList.value = result['data'].list; resultList.value = result['data'].list;

View File

@ -23,7 +23,7 @@ class SearchVideoPanel extends StatelessWidget {
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.only(top: 34), padding: const EdgeInsets.only(top: 36),
child: ListView.builder( child: ListView.builder(
controller: ctr!.scrollController, controller: ctr!.scrollController,
addAutomaticKeepAlives: false, addAutomaticKeepAlives: false,
@ -43,7 +43,7 @@ class SearchVideoPanel extends StatelessWidget {
// 分类筛选 // 分类筛选
Container( Container(
width: double.infinity, width: double.infinity,
height: 34, height: 36,
padding: const EdgeInsets.only(left: 8, top: 0, right: 12), padding: const EdgeInsets.only(left: 8, top: 0, right: 12),
// decoration: BoxDecoration( // decoration: BoxDecoration(
// border: Border( // border: Border(
@ -52,29 +52,53 @@ class SearchVideoPanel extends StatelessWidget {
// ), // ),
// ), // ),
// ), // ),
child: SingleChildScrollView( child: Row(
scrollDirection: Axis.horizontal, children: [
child: Obx( Expanded(
() => Wrap( child: SingleChildScrollView(
// spacing: , scrollDirection: Axis.horizontal,
children: [ child: Obx(
for (var i in controller.filterList) ...[ () => Wrap(
CustomFilterChip( // spacing: ,
label: i['label'], children: [
type: i['type'], for (var i in controller.filterList) ...[
selectedType: controller.selectedType.value, CustomFilterChip(
callFn: (bool selected) async { label: i['label'],
controller.selectedType.value = i['type']; type: i['type'],
ctr!.order.value = i['type'].toString().split('.').last; selectedType: controller.selectedType.value,
SmartDialog.showLoading(msg: 'loooad'); callFn: (bool selected) async {
await ctr!.onRefresh(); controller.selectedType.value = i['type'];
SmartDialog.dismiss(); ctr!.order.value =
}, i['type'].toString().split('.').last;
SmartDialog.showLoading(msg: 'loooad');
await ctr!.onRefresh();
SmartDialog.dismiss();
},
),
]
],
), ),
] ),
], ),
), ),
), const VerticalDivider(indent: 7, endIndent: 8),
const SizedBox(width: 3),
SizedBox(
width: 32,
height: 32,
child: IconButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
),
onPressed: () => controller.onShowFilterDialog(),
icon: Icon(
Icons.filter_list_outlined,
size: 18,
color: Theme.of(context).colorScheme.primary,
),
),
),
],
), ),
), // 放置在ListView.builder()上方的组件 ), // 放置在ListView.builder()上方的组件
], ],
@ -99,7 +123,7 @@ class CustomFilterChip extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SizedBox( return SizedBox(
height: 32, height: 34,
child: FilterChip( child: FilterChip(
padding: const EdgeInsets.only(left: 11, right: 11), padding: const EdgeInsets.only(left: 11, right: 11),
labelPadding: EdgeInsets.zero, labelPadding: EdgeInsets.zero,
@ -130,6 +154,14 @@ class CustomFilterChip extends StatelessWidget {
class VideoPanelController extends GetxController { class VideoPanelController extends GetxController {
RxList<Map> filterList = [{}].obs; RxList<Map> filterList = [{}].obs;
Rx<ArchiveFilterType> selectedType = ArchiveFilterType.values.first.obs; Rx<ArchiveFilterType> selectedType = ArchiveFilterType.values.first.obs;
List<Map<String, dynamic>> timeFiltersList = [
{'label': '全部时长', 'value': 0},
{'label': '0-10分钟', 'value': 1},
{'label': '10-30分钟', 'value': 2},
{'label': '30-60分钟', 'value': 3},
{'label': '60分钟+', 'value': 4},
];
RxInt currentTimeFilterval = 0.obs;
@override @override
void onInit() { void onInit() {
@ -143,5 +175,43 @@ class VideoPanelController extends GetxController {
super.onInit(); super.onInit();
} }
onSelect() {} onShowFilterDialog() {
SmartDialog.show(
animationType: SmartAnimationType.centerFade_otherSlide,
builder: (BuildContext context) {
TextStyle textStyle = Theme.of(context).textTheme.titleMedium!;
return AlertDialog(
title: const Text('时长筛选'),
contentPadding: const EdgeInsets.fromLTRB(0, 15, 0, 20),
content: StatefulBuilder(builder: (context, StateSetter setState) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
for (var i in timeFiltersList) ...[
RadioListTile(
value: i['value'],
autofocus: true,
title: Text(i['label'], style: textStyle),
groupValue: currentTimeFilterval.value,
onChanged: (value) async {
currentTimeFilterval.value = value!;
setState(() {});
SmartDialog.dismiss();
SmartDialog.showToast("${i['label']}」的筛选结果");
SearchPanelController ctr =
Get.find<SearchPanelController>(tag: 'video');
ctr.duration.value = i['value'];
SmartDialog.showLoading(msg: 'loooad');
await ctr.onRefresh();
SmartDialog.dismiss();
},
),
],
],
);
}),
);
},
);
}
} }