feat: Implement show/hide functionality for bottom navigation bar based on route changes

This commit is contained in:
Achintha Isuru
2026-03-03 21:35:59 -05:00
parent 6d9cb64487
commit 630b90ee38
3 changed files with 18 additions and 4 deletions

View File

@@ -17,6 +17,10 @@ class StaffMainCubit extends Cubit<StaffMainState> implements Disposable {
final GetProfileCompletionUseCase _getProfileCompletionUsecase; final GetProfileCompletionUseCase _getProfileCompletionUsecase;
bool _isLoadingCompletion = false; bool _isLoadingCompletion = false;
static const List<String> _hideBottomPaths = <String>[
StaffPaths.benefits,
];
void _onRouteChanged() { void _onRouteChanged() {
if (isClosed) return; if (isClosed) return;
@@ -40,8 +44,10 @@ class StaffMainCubit extends Cubit<StaffMainState> implements Disposable {
newIndex = 4; newIndex = 4;
} }
if (newIndex != state.currentIndex) { final bool showBottomBar = !_hideBottomPaths.any(path.contains);
emit(state.copyWith(currentIndex: newIndex));
if (newIndex != state.currentIndex || showBottomBar != state.showBottomBar) {
emit(state.copyWith(currentIndex: newIndex, showBottomBar: showBottomBar));
} }
} }

View File

@@ -4,18 +4,25 @@ class StaffMainState extends Equatable {
const StaffMainState({ const StaffMainState({
this.currentIndex = 2, // Default to Home this.currentIndex = 2, // Default to Home
this.isProfileComplete = false, this.isProfileComplete = false,
this.showBottomBar = true,
}); });
final int currentIndex; final int currentIndex;
final bool isProfileComplete; final bool isProfileComplete;
final bool showBottomBar;
StaffMainState copyWith({int? currentIndex, bool? isProfileComplete}) { StaffMainState copyWith({
int? currentIndex,
bool? isProfileComplete,
bool? showBottomBar,
}) {
return StaffMainState( return StaffMainState(
currentIndex: currentIndex ?? this.currentIndex, currentIndex: currentIndex ?? this.currentIndex,
isProfileComplete: isProfileComplete ?? this.isProfileComplete, isProfileComplete: isProfileComplete ?? this.isProfileComplete,
showBottomBar: showBottomBar ?? this.showBottomBar,
); );
} }
@override @override
List<Object> get props => <Object>[currentIndex, isProfileComplete]; List<Object> get props => <Object>[currentIndex, isProfileComplete, showBottomBar];
} }

View File

@@ -24,6 +24,7 @@ class StaffMainPage extends StatelessWidget {
body: const RouterOutlet(), body: const RouterOutlet(),
bottomNavigationBar: BlocBuilder<StaffMainCubit, StaffMainState>( bottomNavigationBar: BlocBuilder<StaffMainCubit, StaffMainState>(
builder: (BuildContext context, StaffMainState state) { builder: (BuildContext context, StaffMainState state) {
if (!state.showBottomBar) return const SizedBox.shrink();
return StaffMainBottomBar( return StaffMainBottomBar(
currentIndex: state.currentIndex, currentIndex: state.currentIndex,
onTap: (int index) { onTap: (int index) {