feat: Introduce showBottomBar state to conditionally hide the bottom navigation bar based on specific routes.

This commit is contained in:
Achintha Isuru
2026-02-27 21:43:50 -05:00
parent bba4054143
commit a65181251d
3 changed files with 20 additions and 7 deletions

View File

@@ -14,7 +14,6 @@ class ClientMainCubit extends Cubit<ClientMainState> implements Disposable {
int newIndex = state.currentIndex;
// Detect which tab is active based on the route path
// Using contains() to handle child routes and trailing slashes
if (path.contains(ClientPaths.coverage)) {
newIndex = 0;
} else if (path.contains(ClientPaths.billing)) {
@@ -27,8 +26,15 @@ class ClientMainCubit extends Cubit<ClientMainState> implements Disposable {
newIndex = 4;
}
if (newIndex != state.currentIndex) {
emit(state.copyWith(currentIndex: newIndex));
final bool showBottomBar =
!path.contains(ClientPaths.completionReview) &&
!path.contains(ClientPaths.awaitingApproval);
if (newIndex != state.currentIndex ||
showBottomBar != state.showBottomBar) {
emit(
state.copyWith(currentIndex: newIndex, showBottomBar: showBottomBar),
);
}
}

View File

@@ -3,14 +3,19 @@ import 'package:equatable/equatable.dart';
class ClientMainState extends Equatable {
const ClientMainState({
this.currentIndex = 2, // Default to Home
this.showBottomBar = true,
});
final int currentIndex;
final bool showBottomBar;
ClientMainState copyWith({int? currentIndex}) {
return ClientMainState(currentIndex: currentIndex ?? this.currentIndex);
ClientMainState copyWith({int? currentIndex, bool? showBottomBar}) {
return ClientMainState(
currentIndex: currentIndex ?? this.currentIndex,
showBottomBar: showBottomBar ?? this.showBottomBar,
);
}
@override
List<Object> get props => <Object>[currentIndex];
List<Object> get props => <Object>[currentIndex, showBottomBar];
}

View File

@@ -24,6 +24,8 @@ class ClientMainPage extends StatelessWidget {
body: const RouterOutlet(),
bottomNavigationBar: BlocBuilder<ClientMainCubit, ClientMainState>(
builder: (BuildContext context, ClientMainState state) {
if (!state.showBottomBar) return const SizedBox.shrink();
return ClientMainBottomBar(
currentIndex: state.currentIndex,
onTap: (int index) {