import 'package:flutter/material.dart'; import 'package:adaptive_navbar/adaptive_navbar.dart'; import 'package:nhancepolicy/customAppBar/toastHelper.dart'; import 'package:nhancepolicy/responsive.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:nhancepolicy/responsive.dart'; class CustomAppBar extends StatefulWidget implements PreferredSizeWidget { @override _CustomAppBarState createState() => _CustomAppBarState(); @override Size get preferredSize => Size.fromHeight(kToolbarHeight); } class _CustomAppBarState extends State { bool showBackToHR = true; bool hideInactiveStatus = true; @override void initState() { super.initState(); _checkTokens(); } Future _checkTokens() async { final prefs = await SharedPreferences.getInstance(); final String? hrtoken = prefs.getString('hrtoken'); final String? token = prefs.getString('token'); setState(() { showBackToHR = (hrtoken != null && hrtoken.isNotEmpty) && (token != null && token.isNotEmpty); hideInactiveStatus = token != null && token.isNotEmpty; }); } Future hrLogout(BuildContext context) async { final prefs = await SharedPreferences.getInstance(); final String? hrtoken = prefs.getString('hrtoken'); if (hrtoken != null && hrtoken.isNotEmpty) { prefs.remove('token'); Navigator.pushNamed(context, 'hrDashboard'); } else { await prefs.clear(); Navigator.pushNamed(context, 'phone'); } } Future logout(BuildContext context) async { final prefs = await SharedPreferences.getInstance(); final String? hrtoken = prefs.getString('hrtoken'); final String? token = prefs.getString('token'); if (token != null && token.isNotEmpty) { if (hrtoken != null && hrtoken.isNotEmpty) { await prefs.clear(); Navigator.pushNamed(context, 'hrLogin'); } else { await prefs.clear(); Navigator.pushNamed(context, 'phone'); } } else if (hrtoken != null && hrtoken.isNotEmpty) { await prefs.clear(); 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: 16.0) : EdgeInsets.symmetric(horizontal: 0), child: Row( children: [ // Logo Column Expanded( flex: Responsive.isDesktop(context) ? 3 : 9, child: Row( mainAxisAlignment: Responsive.isDesktop(context) ? MainAxisAlignment.spaceEvenly : MainAxisAlignment.start, children: [ Container( margin: EdgeInsets.only(top: 10, bottom: 10), width: 230, height: 230, child: Image.asset( 'assets/nhance_client_logo.png', fit: BoxFit.contain, ), ), ], ), ), // AdaptiveNavBar Column 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: "Back To HR", onTap: () { hrLogout(context); }, ), NavBarItem( text: "Logout", onTap: () async { logout(context); }, ), ], ), ), ], ), ), ), ), ); } }