From fb60ab9870fab9e0d78877468fcb60476ca64d2b Mon Sep 17 00:00:00 2001 From: Abobo7 <2557826346@qq.com> Date: Wed, 5 Feb 2025 17:55:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=B6=E8=97=8F=E9=A1=B5=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/feedback/view/collection_page.dart | 103 +++++++++++++++++++------ 1 file changed, 78 insertions(+), 25 deletions(-) diff --git a/lib/feedback/view/collection_page.dart b/lib/feedback/view/collection_page.dart index 19d189fe..b25830a7 100644 --- a/lib/feedback/view/collection_page.dart +++ b/lib/feedback/view/collection_page.dart @@ -33,6 +33,9 @@ class _CollectionPageState extends State { bool tap = false; int currentPage = 1; + TextEditingController _searchController = TextEditingController(); + String _searchKeyword = ""; + _getMyCollects({Function(List)? onSuccess, Function? onFail}) { FeedbackService.getFavoritePosts( page: currentPage, @@ -65,7 +68,7 @@ class _CollectionPageState extends State { }); } -//下拉加载 + //下拉加载 _onLoading() { currentPage++; _getMyCollects(onSuccess: (list) { @@ -108,48 +111,99 @@ class _CollectionPageState extends State { _getMyCollects(); } + @override + void dispose() { + _tabController.dispose(); + _searchController.dispose(); + _refreshController.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { ///拆出去单写会刷新错误.. ///收藏List栏,为空时显示无 - var favLists = (ListView.builder( + final filteredFavList = _searchKeyword.trim().isEmpty + ? _favList + : _favList + .where((post) => + post.title.toLowerCase().contains(_searchKeyword.toLowerCase())) + .toList(); + + var favLists = ListView.builder( padding: EdgeInsets.zero, physics: NeverScrollableScrollPhysics(), shrinkWrap: true, + itemCount: filteredFavList.length, itemBuilder: (context, index) { - Widget fav = PostCardNormal( - _favList[index], - ); - return fav; + return PostCardNormal(filteredFavList[index]); }, - itemCount: _favList.length, - )); + ); + var list = ExpandablePageView( controller: _tabController, children: [ AnimatedSwitcher( duration: Duration(milliseconds: 300), child: Builder( - key: ValueKey(_favList.length.isZero), - builder: (context) { - if (_favList.length.isZero) { - return Container( - height: 200, - alignment: Alignment.center, - child: Text("暂无收藏", - style: TextUtil.base.oldThirdAction(context))); - } else { - return Column( - children: [favLists, SizedBox(height: 20.w)], - ); - } - }), + key: ValueKey(filteredFavList.length), + builder: (context) { + if (filteredFavList.isEmpty) { + return Container( + height: 200, + alignment: Alignment.center, + child: Text(_searchKeyword.isEmpty ? "暂无收藏" : "没有匹配的收藏", + style: TextUtil.base.oldThirdAction(context))); + } else { + return Column( + children: [favLists, SizedBox(height: 20.w)], + ); + } + }, + ), ) ], ); Widget body = CustomScrollView( slivers: [ + SliverToBoxAdapter( + child: Padding( + padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.w), + child: TextField( + controller: _searchController, + decoration: InputDecoration( + filled: true, + fillColor: WpyTheme.of(context) + .get(WpyColorKey.primaryBackgroundColor), + contentPadding: + EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.w), + hintText: "搜索收藏帖子", + prefixIcon: Icon(Icons.search), + suffixIcon: _searchKeyword.isNotEmpty + ? IconButton( + icon: Icon(Icons.clear), + onPressed: () { + _searchController.clear(); + setState(() { + _searchKeyword = ""; + }); + }, + ) + : null, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(20.w), + borderSide: BorderSide.none, + ), + ), + onChanged: (value) { + setState(() { + _searchKeyword = value; + }); + }, + ), + ), + ), SliverToBoxAdapter( child: Container( color: WpyTheme.of(context) @@ -225,7 +279,7 @@ class _ExpandablePageViewState extends State void initState() { _heights = widget.children.map((e) => 0.0).toList(); super.initState(); - _pageController = widget.controller // + _pageController = widget.controller ..addListener(() { final _newPage = _pageController.page!.round(); if (_currentPage != _newPage) { @@ -255,12 +309,11 @@ class _ExpandablePageViewState extends State } List get _sizeReportingChildren => widget.children - .asMap() // + .asMap() .map( (index, child) => MapEntry( index, OverflowBox( - //needed, so that parent won't impose its constraints on the children, thus skewing the measurement results. minHeight: 0, maxHeight: double.infinity, alignment: Alignment.topCenter,