mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-16 14:14:01 +08:00
@@ -1,8 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/dialog/export_import.dart';
|
||||
import 'package:PiliPlus/common/widgets/disabled_icon.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/scaffold.dart';
|
||||
import 'package:PiliPlus/common/widgets/sliver_wrap.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models_new/search/search_rcmd/data.dart';
|
||||
@@ -11,8 +8,6 @@ import 'package:PiliPlus/pages/search/widgets/hot_keyword.dart';
|
||||
import 'package:PiliPlus/pages/search/widgets/search_text.dart';
|
||||
import 'package:PiliPlus/utils/em.dart' show Em;
|
||||
import 'package:PiliPlus/utils/extension/size_ext.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/storage_key.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart' hide LayoutBuilder;
|
||||
import 'package:get/get.dart';
|
||||
@@ -50,34 +45,21 @@ class _SearchPageState extends State<SearchPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final trending = _searchController.enableTrending
|
||||
? _buildHotSearch()
|
||||
: null;
|
||||
final rcmd = _searchController.enableSearchRcmd
|
||||
? _buildHotSearch(isTrending: false)
|
||||
: null;
|
||||
|
||||
return Scaffold(
|
||||
final trending = _buildHotSearch();
|
||||
return scaffold(
|
||||
appBar: _buildAppBar,
|
||||
body: Padding(
|
||||
padding: .only(left: padding.left, right: padding.right),
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
if (_searchController.searchSuggestion) _buildSearchSuggest(),
|
||||
_buildSearchSuggest(),
|
||||
if (isPortrait) ...[
|
||||
?trending,
|
||||
trending,
|
||||
_buildHistory,
|
||||
?rcmd,
|
||||
] else if (_searchController.enableTrending ||
|
||||
_searchController.enableSearchRcmd)
|
||||
] else
|
||||
SliverCrossAxisGroup(
|
||||
slivers: [
|
||||
SliverMainAxisGroup(slivers: [?trending, ?rcmd]),
|
||||
_buildHistory,
|
||||
],
|
||||
)
|
||||
else
|
||||
_buildHistory,
|
||||
slivers: [trending, _buildHistory],
|
||||
),
|
||||
SliverPadding(padding: .only(bottom: padding.bottom)),
|
||||
],
|
||||
),
|
||||
@@ -173,11 +155,9 @@ class _SearchPageState extends State<SearchPage> {
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildHotSearch({
|
||||
bool isTrending = true,
|
||||
}) {
|
||||
Widget _buildHotSearch() {
|
||||
final text = Text(
|
||||
isTrending ? '大家都在搜' : '搜索发现',
|
||||
'大家都在搜',
|
||||
strutStyle: const StrutStyle(leading: 0, height: 1),
|
||||
style: theme.textTheme.titleMedium!.copyWith(
|
||||
height: 1,
|
||||
@@ -194,9 +174,7 @@ class _SearchPageState extends State<SearchPage> {
|
||||
return SliverPadding(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
10,
|
||||
!isTrending && (isPortrait || _searchController.enableTrending)
|
||||
? 4
|
||||
: 25,
|
||||
isPortrait ? 4 : 25,
|
||||
4,
|
||||
25,
|
||||
),
|
||||
@@ -208,42 +186,40 @@ class _SearchPageState extends State<SearchPage> {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
isTrending
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
text,
|
||||
const SizedBox(width: 14),
|
||||
TextButton(
|
||||
style: const ButtonStyle(
|
||||
visualDensity: .compact,
|
||||
tapTargetSize: .shrinkWrap,
|
||||
padding: WidgetStatePropertyAll(
|
||||
.symmetric(horizontal: 10),
|
||||
),
|
||||
),
|
||||
onPressed: () => Get.toNamed('/searchTrending'),
|
||||
child: Row(
|
||||
children: [
|
||||
text,
|
||||
const SizedBox(width: 14),
|
||||
TextButton(
|
||||
style: const ButtonStyle(
|
||||
visualDensity: .compact,
|
||||
tapTargetSize: .shrinkWrap,
|
||||
padding: WidgetStatePropertyAll(
|
||||
.symmetric(horizontal: 10),
|
||||
),
|
||||
),
|
||||
onPressed: () => Get.toNamed('/searchTrending'),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'完整榜单',
|
||||
strutStyle: const StrutStyle(
|
||||
leading: 0,
|
||||
height: 1,
|
||||
),
|
||||
style: style,
|
||||
),
|
||||
Icon(
|
||||
size: 18,
|
||||
Icons.keyboard_arrow_right,
|
||||
color: outline,
|
||||
),
|
||||
],
|
||||
Text(
|
||||
'完整榜单',
|
||||
strutStyle: const StrutStyle(
|
||||
leading: 0,
|
||||
height: 1,
|
||||
),
|
||||
style: style,
|
||||
),
|
||||
Icon(
|
||||
size: 18,
|
||||
Icons.keyboard_arrow_right,
|
||||
color: outline,
|
||||
),
|
||||
],
|
||||
)
|
||||
: text,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
TextButton.icon(
|
||||
style: const ButtonStyle(
|
||||
visualDensity: .compact,
|
||||
@@ -252,9 +228,7 @@ class _SearchPageState extends State<SearchPage> {
|
||||
.symmetric(horizontal: 10),
|
||||
),
|
||||
),
|
||||
onPressed: isTrending
|
||||
? _searchController.queryTrendingList
|
||||
: _searchController.queryRecommendList,
|
||||
onPressed: _searchController.queryTrendingList,
|
||||
icon: Icon(
|
||||
Icons.refresh_outlined,
|
||||
size: 18,
|
||||
@@ -274,12 +248,7 @@ class _SearchPageState extends State<SearchPage> {
|
||||
),
|
||||
),
|
||||
Obx(
|
||||
() => _buildHotKey(
|
||||
isTrending
|
||||
? _searchController.trendingState.value
|
||||
: _searchController.recommendData.value,
|
||||
isTrending,
|
||||
),
|
||||
() => _buildHotKey(_searchController.trendingState.value),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -298,11 +267,7 @@ class _SearchPageState extends State<SearchPage> {
|
||||
return SliverPadding(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
10,
|
||||
!isPortrait
|
||||
? 25
|
||||
: _searchController.enableTrending
|
||||
? 0
|
||||
: 6,
|
||||
!isPortrait ? 25 : 0,
|
||||
6,
|
||||
25,
|
||||
),
|
||||
@@ -312,6 +277,7 @@ class _SearchPageState extends State<SearchPage> {
|
||||
padding: const EdgeInsets.fromLTRB(6, 0, 6, 6),
|
||||
sliver: SliverToBoxAdapter(
|
||||
child: Row(
|
||||
mainAxisAlignment: .spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'搜索历史',
|
||||
@@ -321,10 +287,6 @@ class _SearchPageState extends State<SearchPage> {
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
_recordBtn,
|
||||
_exportBtn,
|
||||
const Spacer(),
|
||||
TextButton.icon(
|
||||
style: const ButtonStyle(
|
||||
visualDensity: .compact,
|
||||
@@ -379,64 +341,8 @@ class _SearchPageState extends State<SearchPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget get _recordBtn => Obx(
|
||||
() {
|
||||
bool enable = _searchController.recordSearchHistory.value;
|
||||
return IconButton(
|
||||
iconSize: 22,
|
||||
tooltip: enable ? '记录搜索' : '无痕搜索',
|
||||
icon: DisabledIcon(
|
||||
disable: !enable,
|
||||
child: Icon(
|
||||
Icons.history,
|
||||
color: theme.colorScheme.onSurfaceVariant.withValues(alpha: 0.8),
|
||||
),
|
||||
),
|
||||
style: const ButtonStyle(
|
||||
visualDensity: .comfortable,
|
||||
tapTargetSize: .shrinkWrap,
|
||||
padding: WidgetStatePropertyAll(.zero),
|
||||
),
|
||||
onPressed: () {
|
||||
enable = !enable;
|
||||
_searchController.recordSearchHistory.value = enable;
|
||||
GStorage.setting.put(
|
||||
SettingBoxKey.recordSearchHistory,
|
||||
enable,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Widget get _exportBtn => IconButton(
|
||||
iconSize: 22,
|
||||
tooltip: '导入/导出历史记录',
|
||||
icon: Icon(
|
||||
Icons.import_export_outlined,
|
||||
color: theme.colorScheme.onSurfaceVariant.withValues(alpha: 0.8),
|
||||
),
|
||||
style: const ButtonStyle(
|
||||
visualDensity: .comfortable,
|
||||
tapTargetSize: .shrinkWrap,
|
||||
padding: WidgetStatePropertyAll(.zero),
|
||||
),
|
||||
onPressed: () => showImportExportDialog<List>(
|
||||
context,
|
||||
title: '历史记录',
|
||||
localFileName: () => 'search',
|
||||
onExport: () => jsonEncode(_searchController.historyList),
|
||||
onImport: (json) {
|
||||
final list = List<String>.from(json);
|
||||
_searchController.historyList.value = list;
|
||||
GStorage.historyWord.put('cacheList', list);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
Widget _buildHotKey(
|
||||
LoadingState<SearchRcmdData> loadingState,
|
||||
bool isTrending,
|
||||
) {
|
||||
return switch (loadingState) {
|
||||
Success(:final response) when (response.list?.isNotEmpty ?? false) =>
|
||||
@@ -447,9 +353,7 @@ class _SearchPageState extends State<SearchPage> {
|
||||
Error(:final errMsg) => HttpError(
|
||||
safeArea: false,
|
||||
errMsg: errMsg,
|
||||
onReload: isTrending
|
||||
? _searchController.queryTrendingList
|
||||
: _searchController.queryRecommendList,
|
||||
onReload: _searchController.queryTrendingList,
|
||||
),
|
||||
_ => const SliverToBoxAdapter(),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user