mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
mod: show search count
This commit is contained in:
@@ -4,6 +4,8 @@ class SearchResultController extends GetxController {
|
||||
String? keyword;
|
||||
int tabIndex = 0;
|
||||
|
||||
RxList<int> count = List.generate(5, (_) => -1).toList().obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
@@ -13,19 +13,22 @@ class SearchResultPage extends StatefulWidget {
|
||||
|
||||
class _SearchResultPageState extends State<SearchResultPage>
|
||||
with TickerProviderStateMixin {
|
||||
late SearchResultController? _searchResultController;
|
||||
late SearchResultController _searchResultController;
|
||||
late TabController _tabController;
|
||||
final String _tag = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_searchResultController = Get.put(SearchResultController(),
|
||||
tag: DateTime.now().millisecondsSinceEpoch.toString());
|
||||
_searchResultController = Get.put(
|
||||
SearchResultController(),
|
||||
tag: _tag,
|
||||
);
|
||||
|
||||
_tabController = TabController(
|
||||
vsync: this,
|
||||
length: SearchType.values.length,
|
||||
initialIndex: _searchResultController!.tabIndex,
|
||||
initialIndex: _searchResultController.tabIndex,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,7 +55,7 @@ class _SearchResultPageState extends State<SearchResultPage>
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: Text(
|
||||
'${_searchResultController!.keyword}',
|
||||
'${_searchResultController.keyword}',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
@@ -72,9 +75,19 @@ class _SearchResultPageState extends State<SearchResultPage>
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
tabs: [
|
||||
for (var i in SearchType.values) Tab(text: i.label),
|
||||
],
|
||||
tabs: SearchType.values
|
||||
.map(
|
||||
(item) => Obx(
|
||||
() {
|
||||
int count = _searchResultController
|
||||
.count[SearchType.values.indexOf(item)];
|
||||
return Tab(
|
||||
text:
|
||||
'${item.label}${count != -1 ? ' ${count > 99 ? '99+' : count}' : ''}');
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
isScrollable: true,
|
||||
indicatorWeight: 0,
|
||||
indicatorPadding:
|
||||
@@ -90,14 +103,14 @@ class _SearchResultPageState extends State<SearchResultPage>
|
||||
unselectedLabelColor: Theme.of(context).colorScheme.outline,
|
||||
tabAlignment: TabAlignment.start,
|
||||
onTap: (index) {
|
||||
if (index == _searchResultController!.tabIndex) {
|
||||
if (index == _searchResultController.tabIndex) {
|
||||
Get.find<SearchPanelController>(
|
||||
tag: SearchType.values[index].type +
|
||||
_searchResultController!.keyword!)
|
||||
_searchResultController.keyword!)
|
||||
.animateToTop();
|
||||
}
|
||||
|
||||
_searchResultController!.tabIndex = index;
|
||||
_searchResultController.tabIndex = index;
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -108,9 +121,9 @@ class _SearchResultPageState extends State<SearchResultPage>
|
||||
children: [
|
||||
for (var i in SearchType.values) ...{
|
||||
SearchPanel(
|
||||
keyword: _searchResultController!.keyword,
|
||||
keyword: _searchResultController.keyword,
|
||||
searchType: i,
|
||||
tag: DateTime.now().millisecondsSinceEpoch.toString(),
|
||||
tag: _tag,
|
||||
)
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user