Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-05-30 14:40:13 +08:00
parent 5f2e863cc2
commit 3031d5e3b0
2 changed files with 105 additions and 155 deletions

View File

@@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:math' show max;
import 'package:PiliPlus/grpc/dyn.dart'; import 'package:PiliPlus/grpc/dyn.dart';
import 'package:PiliPlus/grpc/im.dart'; import 'package:PiliPlus/grpc/im.dart';
@@ -11,8 +12,8 @@ import 'package:PiliPlus/utils/utils.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
class MainController extends GetxController { class MainController extends GetxController {
RxList<NavigationBarType> navigationBars = <NavigationBarType>[].obs; List<NavigationBarType> navigationBars = <NavigationBarType>[];
int dynCount = 0; RxInt dynCount = 0.obs;
StreamController<bool>? bottomBarStream; StreamController<bool>? bottomBarStream;
late bool hideTabBar; late bool hideTabBar;
@@ -137,9 +138,8 @@ class MainController extends GetxController {
} }
Future<void> setCount([int count = 0]) async { Future<void> setCount([int count = 0]) async {
if (dynIndex == -1 || dynCount == count) return; if (dynIndex == -1 || dynCount.value == count) return;
dynCount = count; dynCount.value = count;
navigationBars.refresh();
} }
void checkUnreadDynamic() { void checkUnreadDynamic() {
@@ -166,10 +166,10 @@ class MainController extends GetxController {
} else { } else {
navigationBars = navigationBars =
navBarSort.map((i) => NavigationBarType.values[i]).toList(); navBarSort.map((i) => NavigationBarType.values[i]).toList();
if (!navBarSort.contains(defaultHomePage)) defaultHomePage = 0;
} }
this.navigationBars.value = navigationBars; this.navigationBars = navigationBars;
selectedIndex.value = defaultHomePage; selectedIndex.value =
max(0, navigationBars.indexWhere((e) => e.index == defaultHomePage));
} }
@override @override

View File

@@ -207,24 +207,24 @@ class _MainAppState extends State<MainApp>
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
if (useSideBar || !isPortrait) ...[ if (useSideBar || !isPortrait) ...[
Obx( _mainController.navigationBars.length > 1
() => _mainController.navigationBars.length > 1 ? context.isTablet && GStorage.optTabletNav
? context.isTablet && GStorage.optTabletNav ? Column(
? Column( children: [
children: [ SizedBox(
SizedBox( height:
height: MediaQuery.paddingOf(context).top + 50),
MediaQuery.paddingOf(context).top + 50), userAndSearchVertical(theme),
userAndSearchVertical(theme), const Spacer(flex: 2),
const Spacer(flex: 2), Expanded(
Expanded( flex: 5,
flex: 5, child: SizedBox(
child: SizedBox( width: 130,
width: 130, child: MediaQuery.removePadding(
child: MediaQuery.removePadding( context: context,
context: context, removeRight: true,
removeRight: true, child: Obx(
child: NavigationDrawer( () => NavigationDrawer(
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
tilePadding: const EdgeInsets.symmetric( tilePadding: const EdgeInsets.symmetric(
vertical: 5, horizontal: 12), vertical: 5, horizontal: 12),
@@ -237,38 +237,27 @@ class _MainAppState extends State<MainApp>
onDestinationSelected: setIndex, onDestinationSelected: setIndex,
selectedIndex: selectedIndex:
_mainController.selectedIndex.value, _mainController.selectedIndex.value,
children: [ children: _mainController.navigationBars
..._mainController.navigationBars .map(
.map((e) { (e) =>
return NavigationDrawerDestination( NavigationDrawerDestination(
label: Text(e.label), label: Text(e.label),
icon: _buildIcon( icon: _buildIcon(type: e),
type: e, selectedIcon: _buildIcon(
count: e == type: e,
NavigationBarType selected: true,
.dynamics )),
? _mainController.dynCount )
: 0, .toList(),
),
selectedIcon: _buildIcon(
type: e,
count: e ==
NavigationBarType
.dynamics
? _mainController.dynCount
: 0,
selected: true,
),
);
}),
],
), ),
), ),
), ),
), ),
], ),
) ],
: NavigationRail( )
: Obx(
() => NavigationRail(
groupAlignment: 0.5, groupAlignment: 0.5,
selectedIndex: selectedIndex:
_mainController.selectedIndex.value, _mainController.selectedIndex.value,
@@ -276,37 +265,25 @@ class _MainAppState extends State<MainApp>
labelType: NavigationRailLabelType.selected, labelType: NavigationRailLabelType.selected,
leading: userAndSearchVertical(theme), leading: userAndSearchVertical(theme),
destinations: _mainController.navigationBars destinations: _mainController.navigationBars
.map( .map((e) => NavigationRailDestination(
(e) => NavigationRailDestination( label: Text(e.label),
label: Text(e.label), icon: _buildIcon(type: e),
icon: _buildIcon( selectedIcon: _buildIcon(
type: e, type: e,
count: e == NavigationBarType.dynamics selected: true,
? _mainController.dynCount ),
: 0, ))
),
selectedIcon: _buildIcon(
type: e,
count: e == NavigationBarType.dynamics
? _mainController.dynCount
: 0,
selected: true,
),
),
)
.toList(), .toList(),
)
: SafeArea(
right: false,
child: Container(
padding: const EdgeInsets.only(
top: 10,
), ),
width: 80, )
child: userAndSearchVertical(theme), : SafeArea(
), right: false,
child: Container(
padding: const EdgeInsets.only(top: 10),
width: 80,
child: userAndSearchVertical(theme),
), ),
), ),
VerticalDivider( VerticalDivider(
width: 1, width: 1,
indent: MediaQuery.of(context).padding.top, indent: MediaQuery.of(context).padding.top,
@@ -357,75 +334,46 @@ class _MainAppState extends State<MainApp>
duration: const Duration(milliseconds: 500), duration: const Duration(milliseconds: 500),
offset: Offset(0, snapshot.data ? 0 : 1), offset: Offset(0, snapshot.data ? 0 : 1),
child: enableMYBar child: enableMYBar
? Obx( ? _mainController.navigationBars.length > 1
() => _mainController.navigationBars.length > 1 ? Obx(
? NavigationBar( () => NavigationBar(
onDestinationSelected: setIndex, onDestinationSelected: setIndex,
selectedIndex: selectedIndex:
_mainController.selectedIndex.value, _mainController.selectedIndex.value,
destinations: destinations: _mainController.navigationBars
_mainController.navigationBars.map( .map((e) => NavigationDestination(
(e) {
return NavigationDestination(
label: e.label, label: e.label,
icon: _buildIcon( icon: _buildIcon(type: e),
type: e,
count: e ==
NavigationBarType.dynamics
? _mainController.dynCount
: 0,
),
selectedIcon: _buildIcon( selectedIcon: _buildIcon(
type: e, type: e,
count: e ==
NavigationBarType.dynamics
? _mainController.dynCount
: 0,
selected: true, selected: true,
), )))
); .toList(),
}, ),
).toList(), )
) : const SizedBox.shrink()
: const SizedBox.shrink(), : _mainController.navigationBars.length > 1
) ? Obx(
: Obx( () => BottomNavigationBar(
() => _mainController.navigationBars.length > 1 currentIndex:
? BottomNavigationBar( _mainController.selectedIndex.value,
currentIndex: onTap: setIndex,
_mainController.selectedIndex.value, iconSize: 16,
onTap: setIndex, selectedFontSize: 12,
iconSize: 16, unselectedFontSize: 12,
selectedFontSize: 12, type: BottomNavigationBarType.fixed,
unselectedFontSize: 12, items: _mainController.navigationBars
type: BottomNavigationBarType.fixed, .map((e) => BottomNavigationBarItem(
items: _mainController.navigationBars label: e.label,
.map( icon: _buildIcon(type: e),
(e) => BottomNavigationBarItem( activeIcon: _buildIcon(
label: e.label, type: e,
icon: _buildIcon( selected: true,
type: e, )))
count: e == .toList(),
NavigationBarType ),
.dynamics )
? _mainController.dynCount : const SizedBox.shrink(),
: 0,
),
activeIcon: _buildIcon(
type: e,
count: e ==
NavigationBarType
.dynamics
? _mainController.dynCount
: 0,
selected: true,
),
),
)
.toList(),
)
: const SizedBox.shrink(),
),
); );
}, },
), ),
@@ -436,17 +384,19 @@ class _MainAppState extends State<MainApp>
Widget _buildIcon({ Widget _buildIcon({
required NavigationBarType type, required NavigationBarType type,
required int count,
bool selected = false, bool selected = false,
}) { }) {
final icon = selected ? type.selectIcon : type.icon; final icon = selected ? type.selectIcon : type.icon;
return count > 0 return type == NavigationBarType.dynamics
? Badge( ? Obx(
label: _mainController.dynamicBadgeMode == DynamicBadgeMode.number () => Badge(
? Text(count.toString()) isLabelVisible: _mainController.dynCount.value > 0,
: null, label: _mainController.dynamicBadgeMode == DynamicBadgeMode.number
padding: const EdgeInsets.fromLTRB(6, 0, 6, 0), ? Text(_mainController.dynCount.value.toString())
child: icon, : null,
padding: const EdgeInsets.symmetric(horizontal: 6),
child: icon,
),
) )
: icon; : icon;
} }