mod: show search count

This commit is contained in:
bggRGjQaUbCoE
2024-09-28 22:30:00 +08:00
parent 4a82c949af
commit 5e8e6b674f
6 changed files with 107 additions and 34 deletions

View File

@@ -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,
)
}
],