Reapply "opt: msg badge"

This reverts commit f9c365011b.
This commit is contained in:
bggRGjQaUbCoE
2025-01-09 12:34:50 +08:00
parent 7e400701df
commit 41dfab371e
2 changed files with 54 additions and 105 deletions

View File

@@ -42,36 +42,30 @@ class _HomePageState extends State<HomePage>
children: [ children: [
if (!_homeController.useSideBar) customAppBar, if (!_homeController.useSideBar) customAppBar,
if (_homeController.tabs.length > 1) ...[ if (_homeController.tabs.length > 1) ...[
...[ const SizedBox(height: 4),
const SizedBox(height: 4), Container(
SizedBox( height: 42,
width: double.infinity, color: Theme.of(context).colorScheme.surface,
height: 42, child: TabBar(
child: Align( controller: _homeController.tabController,
alignment: Alignment.center, tabs: [
child: TabBar( for (var i in _homeController.tabs) Tab(text: i['label'])
controller: _homeController.tabController, ],
tabs: [ isScrollable: true,
for (var i in _homeController.tabs) Tab(text: i['label']) dividerColor: Colors.transparent,
], enableFeedback: true,
isScrollable: true, splashBorderRadius: BorderRadius.circular(10),
dividerColor: Colors.transparent, tabAlignment: TabAlignment.center,
enableFeedback: true, onTap: (value) {
splashBorderRadius: BorderRadius.circular(10), feedBack();
tabAlignment: TabAlignment.center, if (_homeController.tabController.indexIsChanging.not) {
onTap: (value) { _homeController.tabsCtrList[value]().animateToTop();
feedBack(); }
if (_homeController.tabController.indexIsChanging.not) { },
_homeController.tabsCtrList[value]().animateToTop();
}
},
),
),
), ),
], ),
] else ...[ ] else
const SizedBox(height: 6), const SizedBox(height: 6),
],
Expanded( Expanded(
child: TabBarView( child: TabBarView(
controller: _homeController.tabController, controller: _homeController.tabController,
@@ -90,44 +84,7 @@ class _HomePageState extends State<HomePage>
const SizedBox(width: 4), const SizedBox(width: 4),
Obx( Obx(
() => _homeController.isLogin.value () => _homeController.isLogin.value
? Stack( ? msgBadge(_mainController)
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,
),
),
),
],
)
: const SizedBox.shrink(), : const SizedBox.shrink(),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
@@ -221,7 +178,6 @@ class _HomePageState extends State<HomePage>
Widget get searchBar { Widget get searchBar {
return Expanded( return Expanded(
child: Container( child: Container(
width: 250,
height: 44, height: 44,
clipBehavior: Clip.hardEdge, clipBehavior: Clip.hardEdge,
decoration: BoxDecoration( 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,
),
),
),
);
}

View File

@@ -434,44 +434,7 @@ class _MainAppState extends State<MainApp>
const SizedBox(height: 8), const SizedBox(height: 8),
Obx( Obx(
() => _homeController.isLogin.value () => _homeController.isLogin.value
? Stack( ? msgBadge(_mainController)
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,
),
),
),
],
)
: const SizedBox.shrink(), : const SizedBox.shrink(),
), ),
IconButton( IconButton(