163 lines
5.6 KiB
Dart
Executable File
163 lines
5.6 KiB
Dart
Executable File
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';
|
|
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<CustomAppBar> {
|
|
bool showBackToHR = false;
|
|
// bool isLoading = true; // Add a loading state
|
|
// bool hideInactiveStatus = true;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_checkTokens();
|
|
}
|
|
|
|
Future<void> _checkTokens() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
// final String? hrtoken = prefs.getString('hrtoken');
|
|
final String? hrtoken = prefs.getString('enrollToken');
|
|
final String? token = prefs.getString('token');
|
|
// showBackToHR = prefs.getBool('showBackToHR')!;
|
|
|
|
setState(() {
|
|
showBackToHR = prefs.getBool('showBackToHR')!;
|
|
// showBackToHR = (hrtoken != null && hrtoken.isNotEmpty) &&
|
|
// (token != null && token.isNotEmpty);
|
|
// logDebug((hrtoken != null && hrtoken.isNotEmpty));
|
|
// logDebug((token != null && token.isNotEmpty));
|
|
// logDebug('showBackToHR $showBackToHR');
|
|
|
|
// hideInactiveStatus = token != null && token.isNotEmpty;
|
|
});
|
|
}
|
|
|
|
Future<void> hrLogout(BuildContext context) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final String? hrtoken = prefs.getString('hrtoken');
|
|
|
|
if (hrtoken != null && hrtoken.isNotEmpty) {
|
|
prefs.setBool('showBackToHR', false);
|
|
await prefs.remove('hrSelectArgumentsData');
|
|
prefs.remove('token');
|
|
Navigator.pushNamed(context, 'policies');
|
|
} else {
|
|
await prefs.clear();
|
|
Navigator.pushNamed(context, 'phone');
|
|
}
|
|
}
|
|
|
|
Future<void> 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;
|
|
// if (isLoading) {
|
|
// // Show a loading indicator or a placeholder AppBar while waiting
|
|
// return AppBar(
|
|
// title: Text('Loading...'),
|
|
// );
|
|
// }
|
|
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: 150,
|
|
height: 150,
|
|
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);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|