fix: 搜索页面不刷新

This commit is contained in:
guozhigq
2023-06-25 23:38:03 +08:00
parent 838a141bc7
commit 1ce12f9f28
3 changed files with 14 additions and 11 deletions

View File

@ -13,7 +13,9 @@ import 'widgets/video_panel.dart';
class SearchPanel extends StatefulWidget { class SearchPanel extends StatefulWidget {
String? keyword; String? keyword;
SearchType? searchType; SearchType? searchType;
SearchPanel({required this.keyword, required this.searchType, Key? key}) String? tag;
SearchPanel(
{required this.keyword, required this.searchType, this.tag, Key? key})
: super(key: key); : super(key: key);
@override @override
@ -37,7 +39,7 @@ class _SearchPanelState extends State<SearchPanel>
keyword: widget.keyword, keyword: widget.keyword,
searchType: widget.searchType, searchType: widget.searchType,
), ),
tag: widget.searchType!.type, tag: widget.searchType!.type + widget.tag!,
); );
ScrollController scrollController = ScrollController scrollController =
_searchPanelController!.scrollController; _searchPanelController!.scrollController;

View File

@ -1,6 +1,4 @@
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:pilipala/models/common/search_type.dart';
import 'package:pilipala/pages/searchPanel/index.dart';
class SearchResultController extends GetxController { class SearchResultController extends GetxController {
String? keyword; String? keyword;

View File

@ -13,17 +13,19 @@ class SearchResultPage extends StatefulWidget {
class _SearchResultPageState extends State<SearchResultPage> class _SearchResultPageState extends State<SearchResultPage>
with TickerProviderStateMixin { with TickerProviderStateMixin {
final SearchResultController _searchResultController = late SearchResultController? _searchResultController;
Get.put(SearchResultController());
late TabController? _tabController; late TabController? _tabController;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_searchResultController = Get.put(SearchResultController(),
tag: DateTime.now().millisecondsSinceEpoch.toString());
_tabController = TabController( _tabController = TabController(
vsync: this, vsync: this,
length: SearchType.values.length, length: SearchType.values.length,
initialIndex: _searchResultController.tabIndex, initialIndex: _searchResultController!.tabIndex,
); );
} }
@ -44,7 +46,7 @@ class _SearchResultPageState extends State<SearchResultPage>
child: SizedBox( child: SizedBox(
width: double.infinity, width: double.infinity,
child: Text( child: Text(
'${_searchResultController.keyword}', '${_searchResultController!.keyword}',
style: Theme.of(context).textTheme.titleMedium, style: Theme.of(context).textTheme.titleMedium,
), ),
), ),
@ -77,12 +79,12 @@ class _SearchResultPageState extends State<SearchResultPage>
dividerColor: Colors.transparent, dividerColor: Colors.transparent,
unselectedLabelColor: Theme.of(context).colorScheme.outline, unselectedLabelColor: Theme.of(context).colorScheme.outline,
onTap: (index) { onTap: (index) {
if (index == _searchResultController.tabIndex) { if (index == _searchResultController!.tabIndex) {
Get.find<SearchPanelController>( Get.find<SearchPanelController>(
tag: SearchType.values[index].type) tag: SearchType.values[index].type)
.animateToTop(); .animateToTop();
} }
_searchResultController.tabIndex = index; _searchResultController!.tabIndex = index;
}, },
), ),
), ),
@ -92,8 +94,9 @@ class _SearchResultPageState extends State<SearchResultPage>
children: [ children: [
for (var i in SearchType.values) ...{ for (var i in SearchType.values) ...{
SearchPanel( SearchPanel(
keyword: _searchResultController.keyword, keyword: _searchResultController!.keyword,
searchType: i, searchType: i,
tag: DateTime.now().millisecondsSinceEpoch.toString(),
) )
} }
], ],