feat: Introduce showBottomBar state to conditionally hide the bottom navigation bar based on specific routes.
This commit is contained in:
@@ -14,7 +14,6 @@ class ClientMainCubit extends Cubit<ClientMainState> implements Disposable {
|
|||||||
int newIndex = state.currentIndex;
|
int newIndex = state.currentIndex;
|
||||||
|
|
||||||
// Detect which tab is active based on the route path
|
// Detect which tab is active based on the route path
|
||||||
// Using contains() to handle child routes and trailing slashes
|
|
||||||
if (path.contains(ClientPaths.coverage)) {
|
if (path.contains(ClientPaths.coverage)) {
|
||||||
newIndex = 0;
|
newIndex = 0;
|
||||||
} else if (path.contains(ClientPaths.billing)) {
|
} else if (path.contains(ClientPaths.billing)) {
|
||||||
@@ -27,8 +26,15 @@ class ClientMainCubit extends Cubit<ClientMainState> implements Disposable {
|
|||||||
newIndex = 4;
|
newIndex = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newIndex != state.currentIndex) {
|
final bool showBottomBar =
|
||||||
emit(state.copyWith(currentIndex: newIndex));
|
!path.contains(ClientPaths.completionReview) &&
|
||||||
|
!path.contains(ClientPaths.awaitingApproval);
|
||||||
|
|
||||||
|
if (newIndex != state.currentIndex ||
|
||||||
|
showBottomBar != state.showBottomBar) {
|
||||||
|
emit(
|
||||||
|
state.copyWith(currentIndex: newIndex, showBottomBar: showBottomBar),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,19 @@ import 'package:equatable/equatable.dart';
|
|||||||
class ClientMainState extends Equatable {
|
class ClientMainState extends Equatable {
|
||||||
const ClientMainState({
|
const ClientMainState({
|
||||||
this.currentIndex = 2, // Default to Home
|
this.currentIndex = 2, // Default to Home
|
||||||
|
this.showBottomBar = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
final int currentIndex;
|
final int currentIndex;
|
||||||
|
final bool showBottomBar;
|
||||||
|
|
||||||
ClientMainState copyWith({int? currentIndex}) {
|
ClientMainState copyWith({int? currentIndex, bool? showBottomBar}) {
|
||||||
return ClientMainState(currentIndex: currentIndex ?? this.currentIndex);
|
return ClientMainState(
|
||||||
|
currentIndex: currentIndex ?? this.currentIndex,
|
||||||
|
showBottomBar: showBottomBar ?? this.showBottomBar,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => <Object>[currentIndex];
|
List<Object> get props => <Object>[currentIndex, showBottomBar];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,13 +24,15 @@ class ClientMainPage extends StatelessWidget {
|
|||||||
body: const RouterOutlet(),
|
body: const RouterOutlet(),
|
||||||
bottomNavigationBar: BlocBuilder<ClientMainCubit, ClientMainState>(
|
bottomNavigationBar: BlocBuilder<ClientMainCubit, ClientMainState>(
|
||||||
builder: (BuildContext context, ClientMainState state) {
|
builder: (BuildContext context, ClientMainState state) {
|
||||||
|
if (!state.showBottomBar) return const SizedBox.shrink();
|
||||||
|
|
||||||
return ClientMainBottomBar(
|
return ClientMainBottomBar(
|
||||||
currentIndex: state.currentIndex,
|
currentIndex: state.currentIndex,
|
||||||
onTap: (int index) {
|
onTap: (int index) {
|
||||||
BlocProvider.of<ClientMainCubit>(context).navigateToTab(index);
|
BlocProvider.of<ClientMainCubit>(context).navigateToTab(index);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user