From 41dfab371e6e9aa1ca17ddbfe401a6d54ca49417 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Thu, 9 Jan 2025 12:34:50 +0800 Subject: [PATCH] Reapply "opt: msg badge" This reverts commit f9c365011b73fc2591bd9eeced74b84f038c017b. --- lib/pages/home/view.dart | 120 +++++++++++++++++---------------------- lib/pages/main/view.dart | 39 +------------ 2 files changed, 54 insertions(+), 105 deletions(-) diff --git a/lib/pages/home/view.dart b/lib/pages/home/view.dart index 05eb38bd..8ea93769 100644 --- a/lib/pages/home/view.dart +++ b/lib/pages/home/view.dart @@ -42,36 +42,30 @@ class _HomePageState extends State children: [ if (!_homeController.useSideBar) customAppBar, if (_homeController.tabs.length > 1) ...[ - ...[ - const SizedBox(height: 4), - SizedBox( - width: double.infinity, - height: 42, - child: Align( - alignment: Alignment.center, - child: TabBar( - controller: _homeController.tabController, - tabs: [ - for (var i in _homeController.tabs) Tab(text: i['label']) - ], - isScrollable: true, - dividerColor: Colors.transparent, - enableFeedback: true, - splashBorderRadius: BorderRadius.circular(10), - tabAlignment: TabAlignment.center, - onTap: (value) { - feedBack(); - if (_homeController.tabController.indexIsChanging.not) { - _homeController.tabsCtrList[value]().animateToTop(); - } - }, - ), - ), + const SizedBox(height: 4), + Container( + height: 42, + color: Theme.of(context).colorScheme.surface, + child: TabBar( + controller: _homeController.tabController, + tabs: [ + for (var i in _homeController.tabs) Tab(text: i['label']) + ], + isScrollable: true, + dividerColor: Colors.transparent, + enableFeedback: true, + splashBorderRadius: BorderRadius.circular(10), + tabAlignment: TabAlignment.center, + onTap: (value) { + feedBack(); + if (_homeController.tabController.indexIsChanging.not) { + _homeController.tabsCtrList[value]().animateToTop(); + } + }, ), - ], - ] else ...[ + ), + ] else const SizedBox(height: 6), - ], Expanded( child: TabBarView( controller: _homeController.tabController, @@ -90,44 +84,7 @@ class _HomePageState extends State const SizedBox(width: 4), Obx( () => _homeController.isLogin.value - ? Stack( - clipBehavior: Clip.none, - alignment: Alignment.center, - children: [ - IconButton( - tooltip: '消息', - onPressed: () { - Get.toNamed('/whisper'); - _mainController.msgUnReadCount.value = ''; - }, - icon: const Icon( - Icons.notifications_none, - ), - ), - if (_mainController.msgBadgeMode != - DynamicBadgeMode.hidden && - _mainController.msgUnReadCount.value.isNotEmpty) - Positioned( - top: _mainController.msgBadgeMode == - DynamicBadgeMode.number - ? 8 - : 12, - left: _mainController.msgBadgeMode == - DynamicBadgeMode.number - ? 22 - : 32, - child: IgnorePointer( - child: Badge( - label: _mainController.msgBadgeMode == - DynamicBadgeMode.number - ? Text(_mainController.msgUnReadCount.value - .toString()) - : null, - ), - ), - ), - ], - ) + ? msgBadge(_mainController) : const SizedBox.shrink(), ), const SizedBox(width: 8), @@ -221,7 +178,6 @@ class _HomePageState extends State Widget get searchBar { return Expanded( child: Container( - width: 250, height: 44, clipBehavior: Clip.hardEdge, decoration: BoxDecoration( @@ -301,3 +257,33 @@ class DefaultUser extends StatelessWidget { ); } } + +Widget msgBadge(mainController) { + void toWhisper() { + mainController.msgUnReadCount.value = ''; + mainController.lastCheckUnreadAt = DateTime.now().millisecondsSinceEpoch; + Get.toNamed('/whisper'); + } + + return GestureDetector( + onTap: toWhisper, + child: Badge( + isLabelVisible: mainController.msgBadgeMode != DynamicBadgeMode.hidden && + mainController.msgUnReadCount.value.isNotEmpty, + alignment: mainController.msgBadgeMode == DynamicBadgeMode.number + ? Alignment(0, -0.5) + : Alignment(0.5, -0.5), + label: mainController.msgBadgeMode == DynamicBadgeMode.number && + mainController.msgUnReadCount.value.isNotEmpty + ? Text(mainController.msgUnReadCount.value.toString()) + : null, + child: IconButton( + tooltip: '消息', + onPressed: toWhisper, + icon: const Icon( + Icons.notifications_none, + ), + ), + ), + ); +} diff --git a/lib/pages/main/view.dart b/lib/pages/main/view.dart index 54e13b53..144c60d4 100644 --- a/lib/pages/main/view.dart +++ b/lib/pages/main/view.dart @@ -434,44 +434,7 @@ class _MainAppState extends State const SizedBox(height: 8), Obx( () => _homeController.isLogin.value - ? Stack( - clipBehavior: Clip.none, - alignment: Alignment.center, - children: [ - IconButton( - tooltip: '消息', - onPressed: () { - Get.toNamed('/whisper'); - _mainController.msgUnReadCount.value = ''; - }, - icon: const Icon( - Icons.notifications_none, - ), - ), - if (_mainController.msgBadgeMode != - DynamicBadgeMode.hidden && - _mainController.msgUnReadCount.value.isNotEmpty) - Positioned( - top: _mainController.msgBadgeMode == - DynamicBadgeMode.number - ? 8 - : 12, - left: _mainController.msgBadgeMode == - DynamicBadgeMode.number - ? 22 - : 32, - child: IgnorePointer( - child: Badge( - label: _mainController.msgBadgeMode == - DynamicBadgeMode.number - ? Text(_mainController.msgUnReadCount.value - .toString()) - : null, - ), - ), - ), - ], - ) + ? msgBadge(_mainController) : const SizedBox.shrink(), ), IconButton(