From 9760397f28dc6a325e7f664398decd442045f444 Mon Sep 17 00:00:00 2001 From: wgh19 Date: Wed, 15 May 2024 16:53:39 +0800 Subject: [PATCH] improve search page --- lib/pages/search_page.dart | 135 +++++++++++++++++++++++++++++++++---- 1 file changed, 122 insertions(+), 13 deletions(-) diff --git a/lib/pages/search_page.dart b/lib/pages/search_page.dart index 1976d2d..ce3e35e 100644 --- a/lib/pages/search_page.dart +++ b/lib/pages/search_page.dart @@ -248,7 +248,9 @@ class _TrendingTagsViewState extends LoadingState<_TrendingTagsView, List createState() => _SearchSettingsState(); @@ -269,7 +271,12 @@ class _SearchSettingsState extends State { items: KeywordMatchType.values.map((e) => MenuFlyoutItem( text: Text(e.toString()), - onPressed: () => setState(() => appdata.searchOptions.matchType = e) + onPressed: () { + if(appdata.searchOptions.matchType != e) { + setState(() => appdata.searchOptions.matchType = e); + widget.onChanged?.call(); + } + } ) ).toList(), )), @@ -278,7 +285,12 @@ class _SearchSettingsState extends State { items: FavoriteNumber.values.map((e) => MenuFlyoutItem( text: Text(e.toString()), - onPressed: () => setState(() => appdata.searchOptions.favoriteNumber = e) + onPressed: () { + if(appdata.searchOptions.favoriteNumber != e) { + setState(() => appdata.searchOptions.favoriteNumber = e); + widget.onChanged?.call(); + } + } ) ).toList(), )), @@ -287,7 +299,12 @@ class _SearchSettingsState extends State { items: SearchSort.values.map((e) => MenuFlyoutItem( text: Text(e.toString()), - onPressed: () => setState(() => appdata.searchOptions.sort = e) + onPressed: () { + if(appdata.searchOptions.sort != e) { + setState(() => appdata.searchOptions.sort = e); + widget.onChanged?.call(); + } + } ) ).toList(), )), @@ -304,7 +321,12 @@ class _SearchSettingsState extends State { .paddingLeft(16), DatePicker( selected: appdata.searchOptions.startTime, - onChanged: (t) => setState(() => appdata.searchOptions.startTime = t), + onChanged: (t) { + if(appdata.searchOptions.startTime != t) { + setState(() => appdata.searchOptions.startTime = t); + widget.onChanged?.call(); + } + }, ), const SizedBox(height: 8,) ], @@ -323,7 +345,12 @@ class _SearchSettingsState extends State { .paddingLeft(16), DatePicker( selected: appdata.searchOptions.endTime, - onChanged: (t) => setState(() => appdata.searchOptions.endTime = t), + onChanged: (t) { + if(appdata.searchOptions.endTime != t) { + setState(() => appdata.searchOptions.endTime = t); + widget.onChanged?.call(); + } + }, ), const SizedBox(height: 8,) ], @@ -334,7 +361,12 @@ class _SearchSettingsState extends State { items: AgeLimit.values.map((e) => MenuFlyoutItem( text: Text(e.toString()), - onPressed: () => setState(() => appdata.searchOptions.ageLimit = e) + onPressed: () { + if(appdata.searchOptions.ageLimit != e) { + setState(() => appdata.searchOptions.ageLimit = e); + widget.onChanged?.call(); + } + } ) ).toList(), )), @@ -367,15 +399,24 @@ class SearchResultPage extends StatefulWidget { } class _SearchResultPageState extends MultiPageLoadingState { + late String keyword = widget.keyword; + + late String oldKeyword = widget.keyword; + + late final controller = TextEditingController(text: widget.keyword); + + void search() { + if(keyword != oldKeyword) { + oldKeyword = keyword; + reset(); + } + } + @override Widget buildContent(BuildContext context, final List data) { return CustomScrollView( slivers: [ - SliverToBoxAdapter( - child: Text("${"Search".tl}: ${widget.keyword}", - style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold),) - .paddingVertical(12).paddingHorizontal(16), - ), + buildSearchBar(), SliverMasonryGrid( gridDelegate: const SliverSimpleGridDelegateWithMaxCrossAxisExtent( maxCrossAxisExtent: 240, @@ -395,6 +436,74 @@ class _SearchResultPageState extends MultiPageLoadingState keyword = s, + onSubmitted: (s) => search(), + foregroundDecoration: BoxDecoration( + border: Border.all( + color: ColorScheme.of(context) + .outlineVariant + .withOpacity(0.6)), + borderRadius: BorderRadius.circular(4)), + suffix: MouseRegion( + cursor: SystemMouseCursors.click, + child: GestureDetector( + onTap: search, + child: const Icon( + FluentIcons.search, + size: 16, + ).paddingHorizontal(12), + ), + ), + ), + ), + const SizedBox(width: 4,), + Button( + child: const SizedBox( + height: 42, + child: Center( + child: Icon(FluentIcons.settings), + ), + ), + onPressed: () async{ + bool isChanged = false; + await Navigator.of(context).push( + SideBarRoute(SearchSettings( + onChanged: () => isChanged = true,))); + if(isChanged) { + reset(); + } + }, + ) + ], + ), + ); + }, + ), + ).paddingHorizontal(16), + ), + ), + ).sliverPadding(const EdgeInsets.only(top: 12)); + } + String? nextUrl; @override @@ -403,7 +512,7 @@ class _SearchResultPageState extends MultiPageLoadingState