import 'package:flutter/material.dart'; import 'package:adaptive_navbar/adaptive_navbar.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:nhancepolicy/customAppBar/toastHelper.dart'; import 'package:nhancepolicy/responsive.dart'; import 'package:nhancepolicy/responsive.dart'; import '../service/api_service.dart'; import '../service/token_storage_service.dart'; import 'package:nhancepolicy/logger.dart'; class CustomAppBar extends StatefulWidget implements PreferredSizeWidget { @override _CustomAppBarState createState() => _CustomAppBarState(); @override Size get preferredSize => Size.fromHeight(kToolbarHeight); } class _CustomAppBarState extends State { bool showBackToHR = false; late ApiService apiService; final tokenService = TokenStorageService(); // 🔐 Secure storage instance static const FlutterSecureStorage _secureStorage = FlutterSecureStorage(); // bool isLoading = true; // Add a loading state // bool hideInactiveStatus = true; @override void initState() { super.initState(); apiService = ApiService(context); // _checkTokens(); } Future logout(BuildContext context) async { // final prefs = await SharedPreferences.getInstance(); // final String? hrtoken = prefs.getString('_postToken'); // final String? token = prefs.getString('enrollToken'); // prefs.clear(); logDebug('LocalStorage Cleared'); apiService.logout(); // Navigator.pushNamed(context, 'hrLogin'); } @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: Row( mainAxisSize: MainAxisSize.min, children: [ NavBarItem( text: "Change Branch", onTap: () async { await tokenService.clearBranchSession(); if (!mounted) return; Navigator.pushNamedAndRemoveUntil( context, 'branchSelection', (route) => false, ); }, ), const SizedBox(width: 8), 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, ), ), ), ); } }