opt search panel

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-05-18 17:27:40 +08:00
parent e330359192
commit 0de2603e30
8 changed files with 291 additions and 306 deletions

View File

@@ -2,7 +2,7 @@
enum SearchType {
// all,
// 视频video
video('视频'),
video('视频', hasHeader: true),
// 番剧media_bangumi,
media_bangumi('番剧'),
// 影视media_ft
@@ -16,14 +16,15 @@ enum SearchType {
// 话题topic
// topic,
// 用户bili_user
bili_user('用户'),
bili_user('用户', hasHeader: true),
// 专栏article
article('专栏');
article('专栏', hasHeader: true);
// 相簿photo
// photo
final bool hasHeader;
final String label;
const SearchType(this.label);
const SearchType(this.label, {this.hasHeader = false});
}
// 搜索类型为视频、专栏及相簿时

View File

@@ -37,69 +37,64 @@ class _SearchAllPanelState
@override
Widget buildList(ThemeData theme, List<dynamic> list) {
return SliverPadding(
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom + 80,
),
sliver: SliverWaterfallFlow.extent(
maxCrossAxisExtent: Grid.smallCardWidth * 2,
crossAxisSpacing: StyleString.safeSpace,
lastChildLayoutTypeBuilder: (index) {
if (index == list.length - 1) {
controller.onLoadMore();
}
return index == list.length
? LastChildLayoutType.foot
: LastChildLayoutType.none;
},
children: list
.map(
(item) => switch (item) {
SearchVideoItemModel() => SizedBox(
height: 120,
child: VideoCardH(
videoItem: item,
showPubdate: true,
),
return SliverWaterfallFlow.extent(
maxCrossAxisExtent: Grid.smallCardWidth * 2,
crossAxisSpacing: StyleString.safeSpace,
lastChildLayoutTypeBuilder: (index) {
if (index == list.length - 1) {
controller.onLoadMore();
}
return index == list.length
? LastChildLayoutType.foot
: LastChildLayoutType.none;
},
children: list
.map(
(item) => switch (item) {
SearchVideoItemModel() => SizedBox(
height: 120,
child: VideoCardH(
videoItem: item,
showPubdate: true,
),
List<SearchMBangumiItemModel>() => item.length == 1
? SizedBox(
height: 160,
child: SearchPgcItem(item: item.first),
)
: SizedBox(
height: Grid.smallCardWidth / 2 / 0.75 +
MediaQuery.textScalerOf(context).scale(60),
child: ListView.builder(
padding: const EdgeInsets.only(bottom: 7),
physics: const AlwaysScrollableScrollPhysics(),
scrollDirection: Axis.horizontal,
itemCount: item.length,
itemBuilder: (context, index) {
return Container(
width: Grid.smallCardWidth / 2,
margin: EdgeInsets.only(
left: StyleString.safeSpace,
right: index == item.length - 1
? StyleString.safeSpace
: 0,
),
child: BangumiCardVSearch(item: item[index]),
);
},
),
),
List<SearchMBangumiItemModel>() => item.length == 1
? SizedBox(
height: 160,
child: SearchPgcItem(item: item.first),
)
: SizedBox(
height: Grid.smallCardWidth / 2 / 0.75 +
MediaQuery.textScalerOf(context).scale(60),
child: ListView.builder(
padding: const EdgeInsets.only(bottom: 7),
physics: const AlwaysScrollableScrollPhysics(),
scrollDirection: Axis.horizontal,
itemCount: item.length,
itemBuilder: (context, index) {
return Container(
width: Grid.smallCardWidth / 2,
margin: EdgeInsets.only(
left: StyleString.safeSpace,
right: index == item.length - 1
? StyleString.safeSpace
: 0,
),
child: BangumiCardVSearch(item: item[index]),
);
},
),
SearchUserItemModel() => Padding(
padding: const EdgeInsets.only(bottom: 5),
child: SearchUserItem(
item: item,
),
SearchUserItemModel() => Padding(
padding: const EdgeInsets.only(bottom: 5),
child: SearchUserItem(
item: item,
),
_ => const SizedBox.shrink(),
},
)
.toList(),
),
),
_ => const SizedBox.shrink(),
},
)
.toList(),
);
}
}

View File

@@ -32,77 +32,72 @@ class _SearchArticlePanelState extends CommonSearchPanelState<
);
@override
Widget buildList(ThemeData theme, List<SearchArticleItemModel> list) {
return SliverMainAxisGroup(
slivers: [
SliverPersistentHeader(
pinned: false,
floating: true,
delegate: CustomSliverPersistentHeaderDelegate(
extent: 40,
bgColor: theme.colorScheme.surface,
child: Container(
height: 40,
padding: const EdgeInsets.only(left: 25, right: 12),
child: Row(
children: [
Obx(
() => Text(
'排序: ${controller.orderFiltersList[controller.currentOrderFilterval.value]['label']}',
maxLines: 1,
style: TextStyle(color: theme.colorScheme.outline),
),
),
const Spacer(),
Obx(
() => Text(
'分区: ${controller.zoneFiltersList[controller.currentZoneFilterval.value]['label']}',
maxLines: 1,
style: TextStyle(color: theme.colorScheme.outline),
),
),
const Spacer(),
SizedBox(
width: 32,
height: 32,
child: IconButton(
tooltip: '筛选',
style: ButtonStyle(
padding: WidgetStateProperty.all(EdgeInsets.zero),
),
onPressed: () {
controller.onShowFilterDialog(context);
},
icon: Icon(
Icons.filter_list_outlined,
size: 18,
color: theme.colorScheme.primary,
),
),
),
],
Widget buildHeader(ThemeData theme) {
return SliverPersistentHeader(
pinned: false,
floating: true,
delegate: CustomSliverPersistentHeaderDelegate(
extent: 40,
bgColor: theme.colorScheme.surface,
child: Container(
height: 40,
padding: const EdgeInsets.only(left: 25, right: 12),
child: Row(
children: [
Obx(
() => Text(
'排序: ${controller.orderFiltersList[controller.currentOrderFilterval.value]['label']}',
maxLines: 1,
style: TextStyle(color: theme.colorScheme.outline),
),
),
),
const Spacer(),
Obx(
() => Text(
'分区: ${controller.zoneFiltersList[controller.currentZoneFilterval.value]['label']}',
maxLines: 1,
style: TextStyle(color: theme.colorScheme.outline),
),
),
const Spacer(),
SizedBox(
width: 32,
height: 32,
child: IconButton(
tooltip: '筛选',
style: ButtonStyle(
padding: WidgetStateProperty.all(EdgeInsets.zero),
),
onPressed: () {
controller.onShowFilterDialog(context);
},
icon: Icon(
Icons.filter_list_outlined,
size: 18,
color: theme.colorScheme.primary,
),
),
),
],
),
),
SliverPadding(
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom + 80,
),
sliver: SliverGrid(
gridDelegate: Grid.videoCardHDelegate(context),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
if (index == list.length - 1) {
controller.onLoadMore();
}
return SearchArticleItem(item: list[index]);
},
childCount: list.length,
),
),
),
],
),
);
}
@override
Widget buildList(ThemeData theme, List<SearchArticleItemModel> list) {
return SliverGrid(
gridDelegate: Grid.videoCardHDelegate(context),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
if (index == list.length - 1) {
controller.onLoadMore();
}
return SearchArticleItem(item: list[index]);
},
childCount: list.length,
),
);
}
}

View File

@@ -34,10 +34,9 @@ class _SearchLivePanelState extends CommonSearchPanelState<SearchLivePanel,
@override
Widget buildList(ThemeData theme, List<SearchLiveItemModel> list) {
return SliverPadding(
padding: EdgeInsets.only(
padding: const EdgeInsets.only(
left: StyleString.safeSpace,
right: StyleString.safeSpace,
bottom: MediaQuery.paddingOf(context).bottom + 80,
),
sliver: SliverGrid(
gridDelegate: SliverGridDelegateWithExtentAndRatio(

View File

@@ -32,23 +32,19 @@ class _SearchPgcPanelState extends CommonSearchPanelState<SearchPgcPanel,
@override
Widget buildList(ThemeData theme, List<SearchMBangumiItemModel> list) {
return SliverPadding(
padding:
EdgeInsets.only(bottom: MediaQuery.paddingOf(context).bottom + 80),
sliver: SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: Grid.smallCardWidth * 2,
mainAxisExtent: 160,
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
if (index == list.length - 1) {
controller.onLoadMore();
}
return SearchPgcItem(item: list[index]);
},
childCount: list.length,
),
return SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: Grid.smallCardWidth * 2,
mainAxisExtent: 160,
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
if (index == list.length - 1) {
controller.onLoadMore();
}
return SearchPgcItem(item: list[index]);
},
childCount: list.length,
),
);
}

View File

@@ -32,81 +32,77 @@ class _SearchUserPanelState extends CommonSearchPanelState<SearchUserPanel,
);
@override
Widget buildList(ThemeData theme, List<SearchUserItemModel> list) {
return SliverMainAxisGroup(
slivers: [
SliverPersistentHeader(
pinned: false,
floating: true,
delegate: CustomSliverPersistentHeaderDelegate(
extent: 40,
bgColor: theme.colorScheme.surface,
child: Container(
height: 40,
padding: const EdgeInsets.only(left: 25, right: 12),
child: Row(
children: [
Obx(
() => Text(
'排序: ${controller.orderFiltersList[controller.currentOrderFilterval.value]['label']}',
maxLines: 1,
style: TextStyle(color: theme.colorScheme.outline),
),
),
const Spacer(),
Obx(
() => Text(
'用户类型: ${controller.userTypeFiltersList[controller.currentUserTypeFilterval.value]['label']}',
maxLines: 1,
style: TextStyle(color: theme.colorScheme.outline),
),
),
const Spacer(),
SizedBox(
width: 32,
height: 32,
child: IconButton(
tooltip: '筛选',
style: ButtonStyle(
padding: WidgetStateProperty.all(EdgeInsets.zero),
),
onPressed: () {
controller.onShowFilterDialog(context);
},
icon: Icon(
Icons.filter_list_outlined,
size: 18,
color: theme.colorScheme.primary,
),
),
),
],
Widget buildHeader(ThemeData theme) {
return SliverPersistentHeader(
pinned: false,
floating: true,
delegate: CustomSliverPersistentHeaderDelegate(
extent: 40,
bgColor: theme.colorScheme.surface,
child: Container(
height: 40,
padding: const EdgeInsets.only(left: 25, right: 12),
child: Row(
children: [
Obx(
() => Text(
'排序: ${controller.orderFiltersList[controller.currentOrderFilterval.value]['label']}',
maxLines: 1,
style: TextStyle(color: theme.colorScheme.outline),
),
),
),
const Spacer(),
Obx(
() => Text(
'用户类型: ${controller.userTypeFiltersList[controller.currentUserTypeFilterval.value]['label']}',
maxLines: 1,
style: TextStyle(color: theme.colorScheme.outline),
),
),
const Spacer(),
SizedBox(
width: 32,
height: 32,
child: IconButton(
tooltip: '筛选',
style: ButtonStyle(
padding: WidgetStateProperty.all(EdgeInsets.zero),
),
onPressed: () {
controller.onShowFilterDialog(context);
},
icon: Icon(
Icons.filter_list_outlined,
size: 18,
color: theme.colorScheme.primary,
),
),
),
],
),
),
SliverPadding(
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom + 80),
sliver: SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: Grid.smallCardWidth * 2,
mainAxisExtent: 66,
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
if (index == list.length - 1) {
controller.onLoadMore();
}
return SearchUserItem(
item: list[index],
);
},
childCount: list.length,
),
),
),
],
),
);
}
@override
Widget buildList(ThemeData theme, List<SearchUserItemModel> list) {
return SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: Grid.smallCardWidth * 2,
mainAxisExtent: 66,
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
if (index == list.length - 1) {
controller.onLoadMore();
}
return SearchUserItem(
item: list[index],
);
},
childCount: list.length,
),
);
}
}

View File

@@ -34,93 +34,89 @@ class _SearchVideoPanelState extends CommonSearchPanelState<SearchVideoPanel,
);
@override
Widget buildList(ThemeData theme, List<SearchVideoItemModel> list) {
return SliverMainAxisGroup(
slivers: [
SliverPersistentHeader(
pinned: false,
floating: true,
delegate: CustomSliverPersistentHeaderDelegate(
extent: 34,
bgColor: theme.colorScheme.surface,
child: Container(
height: 34,
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
children: [
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Wrap(
children: [
for (var i in controller.filterList) ...[
Obx(
() => SearchText(
fontSize: 13,
text: i['label'],
bgColor: Colors.transparent,
textColor:
controller.selectedType.value == i['type']
? theme.colorScheme.primary
: theme.colorScheme.outline,
onTap: (value) async {
controller.selectedType.value = i['type'];
controller.order.value =
i['type'].toString().split('.').last;
SmartDialog.showLoading(msg: 'loading');
await controller.onReload();
SmartDialog.dismiss();
},
),
),
]
],
),
),
Widget buildHeader(ThemeData theme) {
return SliverPersistentHeader(
pinned: false,
floating: true,
delegate: CustomSliverPersistentHeaderDelegate(
extent: 34,
bgColor: theme.colorScheme.surface,
child: Container(
height: 34,
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
children: [
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Wrap(
children: [
for (var i in controller.filterList) ...[
Obx(
() => SearchText(
fontSize: 13,
text: i['label'],
bgColor: Colors.transparent,
textColor:
controller.selectedType.value == i['type']
? theme.colorScheme.primary
: theme.colorScheme.outline,
onTap: (value) async {
controller.selectedType.value = i['type'];
controller.order.value =
i['type'].toString().split('.').last;
SmartDialog.showLoading(msg: 'loading');
await controller.onReload();
SmartDialog.dismiss();
},
),
),
]
],
),
const VerticalDivider(indent: 7, endIndent: 8),
const SizedBox(width: 3),
SizedBox(
width: 32,
height: 32,
child: IconButton(
tooltip: '筛选',
style: ButtonStyle(
padding: WidgetStateProperty.all(EdgeInsets.zero),
),
onPressed: () => controller.onShowFilterDialog(context),
icon: Icon(
Icons.filter_list_outlined,
size: 18,
color: theme.colorScheme.primary,
),
),
),
],
),
),
),
const VerticalDivider(indent: 7, endIndent: 8),
const SizedBox(width: 3),
SizedBox(
width: 32,
height: 32,
child: IconButton(
tooltip: '筛选',
style: ButtonStyle(
padding: WidgetStateProperty.all(EdgeInsets.zero),
),
onPressed: () => controller.onShowFilterDialog(context),
icon: Icon(
Icons.filter_list_outlined,
size: 18,
color: theme.colorScheme.primary,
),
),
),
],
),
),
SliverPadding(
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom + 80),
sliver: SliverGrid(
gridDelegate: Grid.videoCardHDelegate(context),
delegate: SliverChildBuilderDelegate(
(context, index) {
if (index == list.length - 1) {
controller.onLoadMore();
}
return VideoCardH(
videoItem: list[index],
showPubdate: true,
);
},
childCount: list.length,
),
),
),
],
),
);
}
@override
Widget buildList(ThemeData theme, List<SearchVideoItemModel> list) {
return SliverGrid(
gridDelegate: Grid.videoCardHDelegate(context),
delegate: SliverChildBuilderDelegate(
(context, index) {
if (index == list.length - 1) {
controller.onLoadMore();
}
return VideoCardH(
videoItem: list[index],
showPubdate: true,
);
},
childCount: list.length,
),
);
}
}

View File

@@ -45,6 +45,7 @@ abstract class CommonSearchPanelState<
controller: controller.scrollController,
physics: const AlwaysScrollableScrollPhysics(),
slivers: [
if (widget.searchType.hasHeader) buildHeader(theme),
Obx(() => _buildBody(theme, controller.loadingState.value)),
],
),
@@ -105,7 +106,11 @@ abstract class CommonSearchPanelState<
)
: _builLoading,
Success(:var response) => response?.isNotEmpty == true
? buildList(theme, response!)
? SliverPadding(
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom + 80),
sliver: buildList(theme, response!),
)
: HttpError(
onReload: controller.onReload,
),
@@ -116,5 +121,7 @@ abstract class CommonSearchPanelState<
};
}
Widget buildHeader(ThemeData theme) => throw UnimplementedError();
Widget buildList(ThemeData theme, List<T> list);
}