Floating NavBar

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-04-02 12:37:49 +08:00
parent cdc1720358
commit de3505ce07
8 changed files with 870 additions and 60 deletions

View File

@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:PiliPlus/common/assets.dart';
import 'package:PiliPlus/common/constants.dart';
import 'package:PiliPlus/common/style.dart';
import 'package:PiliPlus/common/widgets/floating_navigation_bar.dart';
import 'package:PiliPlus/common/widgets/flutter/pop_scope.dart';
import 'package:PiliPlus/common/widgets/flutter/tabs.dart';
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
@@ -270,67 +271,88 @@ class _MainAppState extends PopScopeState<MainApp>
}
Widget? get _bottomNav {
Widget? bottomNav = _mainController.navigationBars.length > 1
? _mainController.enableMYBar
? Obx(
() => NavigationBar(
maintainBottomViewPadding: true,
onDestinationSelected: _mainController.setIndex,
selectedIndex: _mainController.selectedIndex.value,
destinations: _mainController.navigationBars
.map(
(e) => NavigationDestination(
label: e.label,
icon: _buildIcon(type: e),
selectedIcon: _buildIcon(type: e, selected: true),
),
)
.toList(),
Widget? bottomNav;
if (_mainController.navigationBars.length > 1) {
if (_mainController.floatingNavBar) {
bottomNav = Obx(
() => FloatingNavigationBar(
onDestinationSelected: _mainController.setIndex,
selectedIndex: _mainController.selectedIndex.value,
destinations: _mainController.navigationBars
.map(
(e) => FloatingNavigationDestination(
label: e.label,
icon: _buildIcon(type: e),
selectedIcon: _buildIcon(type: e, selected: true),
),
)
: Obx(
() => BottomNavigationBar(
currentIndex: _mainController.selectedIndex.value,
onTap: _mainController.setIndex,
iconSize: 16,
selectedFontSize: 12,
unselectedFontSize: 12,
type: .fixed,
items: _mainController.navigationBars
.map(
(e) => BottomNavigationBarItem(
label: e.label,
icon: _buildIcon(type: e),
activeIcon: _buildIcon(type: e, selected: true),
),
)
.toList(),
.toList(),
),
);
} else if (_mainController.enableMYBar) {
bottomNav = Obx(
() => NavigationBar(
maintainBottomViewPadding: true,
onDestinationSelected: _mainController.setIndex,
selectedIndex: _mainController.selectedIndex.value,
destinations: _mainController.navigationBars
.map(
(e) => NavigationDestination(
label: e.label,
icon: _buildIcon(type: e),
selectedIcon: _buildIcon(type: e, selected: true),
),
)
: null;
if (bottomNav != null && _mainController.hideBottomBar) {
if (_mainController.barOffset case final barOffset?) {
return Obx(
() => FractionalTranslation(
translation: Offset(
0.0,
barOffset.value / Style.topBarHeight,
),
child: bottomNav,
.toList(),
),
);
} else {
bottomNav = Obx(
() => BottomNavigationBar(
currentIndex: _mainController.selectedIndex.value,
onTap: _mainController.setIndex,
iconSize: 16,
selectedFontSize: 12,
unselectedFontSize: 12,
type: .fixed,
items: _mainController.navigationBars
.map(
(e) => BottomNavigationBarItem(
label: e.label,
icon: _buildIcon(type: e),
activeIcon: _buildIcon(type: e, selected: true),
),
)
.toList(),
),
);
}
if (_mainController.showBottomBar case final showBottomBar?) {
return Obx(
() => AnimatedSlide(
curve: Curves.easeInOutCubicEmphasized,
duration: const Duration(milliseconds: 500),
offset: Offset(0, showBottomBar.value ? 0 : 1),
child: bottomNav,
),
);
if (_mainController.hideBottomBar) {
if (_mainController.barOffset case final barOffset?) {
return Obx(
() => FractionalTranslation(
translation: Offset(
0.0,
barOffset.value / Style.topBarHeight,
),
child: bottomNav,
),
);
}
if (_mainController.showBottomBar case final showBottomBar?) {
return Obx(
() => AnimatedSlide(
curve: Curves.easeInOutCubicEmphasized,
duration: const Duration(milliseconds: 500),
offset: Offset(0, showBottomBar.value ? 0 : 1),
child: bottomNav,
),
);
}
}
}
return bottomNav;
}