From 8ce50267783ffd19b56436f16cbb4324b797d0ca Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Wed, 8 Jan 2025 21:26:18 +0800 Subject: [PATCH] opt: msg badge Signed-off-by: bggRGjQaUbCoE --- lib/pages/home/view.dart | 58 +++++++++++++++------------------------- lib/pages/main/view.dart | 58 +++++++++++++++------------------------- 2 files changed, 44 insertions(+), 72 deletions(-) diff --git a/lib/pages/home/view.dart b/lib/pages/home/view.dart index 05eb38bd..4f1d7c96 100644 --- a/lib/pages/home/view.dart +++ b/lib/pages/home/view.dart @@ -90,43 +90,29 @@ 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, - ), + ? 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: () { + 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, - ), - ), - ), - ], + ), ) : const SizedBox.shrink(), ), diff --git a/lib/pages/main/view.dart b/lib/pages/main/view.dart index 54e13b53..484365ad 100644 --- a/lib/pages/main/view.dart +++ b/lib/pages/main/view.dart @@ -434,43 +434,29 @@ 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, - ), + ? 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: () { + 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, - ), - ), - ), - ], + ), ) : const SizedBox.shrink(), ),