253 lines
8.9 KiB
Dart
Executable File
253 lines
8.9 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
|
import 'package:nhance_app_pwa/logger.dart';
|
|
import 'package:adaptive_navbar/adaptive_navbar.dart';
|
|
import 'package:flutter_svg/svg.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:nhance_app_pwa/customAppBar/responsive.dart';
|
|
|
|
import '../pages/postEnrollment/service/api_service.dart';
|
|
import '../pages/service/SessionManager.dart';
|
|
import '../pages/service/TokenService.dart';
|
|
import '../pages/service/popup_helper.dart';
|
|
class CustomAppBar extends StatefulWidget implements PreferredSizeWidget {
|
|
/// When true, shows only the client logo (no nav menu).
|
|
final bool logoOnly;
|
|
|
|
const CustomAppBar({super.key, this.logoOnly = false});
|
|
|
|
@override
|
|
_CustomAppBarState createState() => _CustomAppBarState();
|
|
|
|
@override
|
|
Size get preferredSize => Size.fromHeight(kToolbarHeight);
|
|
}
|
|
class _CustomAppBarState extends State<CustomAppBar> {
|
|
@override
|
|
Size get preferredSize => Size.fromHeight(kToolbarHeight);
|
|
late ApiService apiService;
|
|
final session = SessionManager();
|
|
bool isRetailLoggedIn = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
apiService = ApiService(context);
|
|
checkRetailOrNot();
|
|
}
|
|
|
|
checkRetailOrNot() async {
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
isRetailLoggedIn = prefs.getBool('isRetailLoggedIn') ?? false;
|
|
logDebug('isRetailLoggedIn Navbar $isRetailLoggedIn');
|
|
}
|
|
|
|
void handleMenuTap(VoidCallback? action) {
|
|
if (isRetailLoggedIn) {
|
|
|
|
return;
|
|
}
|
|
action?.call();
|
|
}
|
|
|
|
|
|
Future<void> logout(BuildContext context) async {
|
|
final String? token = await TokenService.getPostToken();
|
|
|
|
if (token != null && token.isNotEmpty) {
|
|
await SessionManager().clear();
|
|
context.go('/login');
|
|
// Navigator.pushNamed(context, 'phone');
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final sw = MediaQuery.of(context).size.width;
|
|
|
|
return Scaffold(
|
|
backgroundColor: Color(0xFFFFFCE5), // Set background color for AppBar
|
|
appBar: PreferredSize(
|
|
preferredSize: widget.preferredSize,
|
|
child: SafeArea(
|
|
child: Container(
|
|
// padding: Responsive.isDesktop(context)
|
|
// ? EdgeInsets.symmetric(horizontal: 46.0)
|
|
// : EdgeInsets.symmetric(horizontal: 0),
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: MediaQuery.of(context).size.width *
|
|
(Responsive.isDesktop(context) ? 0.03 : 0.02),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
// Logo Column
|
|
// Expanded(
|
|
// // flex: Responsive.isDesktop(context) ? 1 : 9,
|
|
// child:
|
|
Row(
|
|
mainAxisAlignment: Responsive.isDesktop(context)
|
|
? MainAxisAlignment.spaceEvenly
|
|
: MainAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10, bottom: 10),
|
|
width: 150,
|
|
height: 150,
|
|
child: Image.asset(
|
|
'assets/nhance_client_logo.png',
|
|
fit: BoxFit.contain,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
// ),
|
|
// AdaptiveNavBar Column
|
|
|
|
// Expanded(
|
|
// // flex: Responsive.isDesktop(context) ? 1 : 9,
|
|
// child:
|
|
if (!widget.logoOnly && Responsive.isDesktop(context))
|
|
Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
NavBarItem(
|
|
text: "Home",
|
|
onTap: () => handleMenuTap(() {
|
|
context.push('/home');
|
|
}),
|
|
),
|
|
NavBarItem(
|
|
text: "Claims",
|
|
onTap: () => handleMenuTap(() {
|
|
context.push('/claims');
|
|
}),
|
|
),
|
|
NavBarItem(
|
|
text: "FAQs",
|
|
onTap: () => handleMenuTap(() {
|
|
context.push('/faqs');
|
|
}),
|
|
),
|
|
NavBarItem(
|
|
text: "Profile",
|
|
onTap: () => handleMenuTap(() {
|
|
context.push('/profile');
|
|
}),
|
|
),
|
|
NavBarItem(
|
|
text: "Help",
|
|
onTap: () => handleMenuTap(() {
|
|
context.push('/help');
|
|
}),
|
|
),
|
|
|
|
// NavBarItem(
|
|
// text: "Wellness",
|
|
// onTap: () => handleMenuTap(() {
|
|
// PopupHelper.showRedirectPopup(
|
|
// context: context,
|
|
// apiService: apiService,
|
|
// empPrimaryId: session.empPrimaryId,
|
|
// );
|
|
// }),
|
|
// ),
|
|
NavBarItem(
|
|
text: "Logout",
|
|
onTap: () {
|
|
logout(context);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
// )
|
|
|
|
// Expanded(
|
|
// flex: Responsive.isDesktop(context) ? 9 : 3,
|
|
// child: AdaptiveNavBar(
|
|
// screenWidth: sw,
|
|
// backgroundColor: Color(0xFFFFFCE5),
|
|
// leading:
|
|
// Container(), // Set an empty container as we have the logo separately
|
|
// title: Text(''),
|
|
// navBarItems: [
|
|
// // if (Responsive.isDesktop(context))
|
|
// // if (hideInactiveStatus)
|
|
// // NavBarItem(
|
|
// // text: "Inactive Policy",
|
|
// // onTap: () {
|
|
// // Navigator.pushNamed(context, 'oldPolicy');
|
|
// // },
|
|
// // ),
|
|
// // if (showBackToHR)
|
|
// NavBarItem(
|
|
// text: "Change Branch",
|
|
// onTap: () async {
|
|
// final prefs = await SharedPreferences.getInstance();
|
|
// await prefs.remove('selected_branch');
|
|
// await prefs.remove('decoded_token');
|
|
// await prefs.remove('clientLogo');
|
|
// await prefs.remove('clientName');
|
|
// await prefs.remove('empAllowed_modules');
|
|
// await prefs.remove('empClientBranchId');
|
|
// await prefs.remove('empClientId');
|
|
// await prefs.remove('empEmail');
|
|
// await prefs.remove('empHrId');
|
|
// await prefs.remove('empPrimaryId');
|
|
// await prefs.remove('enrollmentAllowed_modules');
|
|
// await prefs.remove('enrollmentClient_id');
|
|
// await prefs.remove('enrollmentEmpClientBranchId');
|
|
// await prefs.remove('enrollmentEmpPrimaryId');
|
|
// await prefs.remove('enrollmentHrId');
|
|
// await prefs.remove('token');
|
|
// Navigator.pushNamed(context, 'branchSelection');
|
|
// },
|
|
// ),
|
|
// NavBarItem(
|
|
// text: "Logout",
|
|
// onTap: () async {
|
|
// logout(context);
|
|
// },
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// ),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
}
|
|
class NavBarItem extends StatelessWidget {
|
|
final String text;
|
|
final VoidCallback? onTap;
|
|
|
|
const NavBarItem({
|
|
Key? key,
|
|
required this.text,
|
|
this.onTap,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return InkWell(
|
|
borderRadius: BorderRadius.circular(6),
|
|
onTap: onTap,
|
|
hoverColor: const Color(0xFFF4F3E7), // subtle hover background
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
child: Text(
|
|
text,
|
|
style: const TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
color: Colors.black87,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |