post_enrollment_app/lib/customAppBar/enrollmentAppBar.dart
2024-08-05 12:13:18 +05:30

136 lines
4.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:adaptive_navbar/adaptive_navbar.dart';
import 'package:nhance_app_pwa/customAppBar/responsive.dart';
import 'package:nhance_app_pwa/customAppBar/toastHelper.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../models/platform_helper_mobile.dart'
if (dart.library.html) '../models/platform_helper_other.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 = true;
bool hideInactiveStatus = true;
dynamic empStatus;
@override
void initState() {
super.initState();
getEmpStatus();
}
Future<void> getEmpStatus() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
empStatus = prefs.getString('emp_status');
}
Future<void> logout(BuildContext context) async {
// final prefs = await SharedPreferences.getInstance();
// final String? token = prefs.getString('token');
//
// if (token != null && token.isNotEmpty) {
// await prefs.clear();
// Navigator.pushNamed(context, 'login');
// }
if (isMobilePlatform()) {
final SharedPreferences prefs = await SharedPreferences.getInstance();
// Get the value of the mobile_number key
String? mobileNumber = prefs.getString('empMobileNo');
// Clear all keys
await prefs.clear();
// Re-set the mobile_number key
if (mobileNumber != null) {
await prefs.setString('empMobileNo', mobileNumber);
}
ToastHelper.showSuccessToast(context, 'logout');
// Navigate to login page
Navigator.pushNamed(context, 'login');
} else {
final prefs = await SharedPreferences.getInstance();
await prefs.clear();
Navigator.pushNamed(context, 'login');
}
}
@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
if (empStatus != 'enrolled')
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))
NavBarItem(
text: "",
onTap: () {
// Navigator.pushNamed(context, 'oldPolicy');
},
),
NavBarItem(
text: "Logout",
onTap: () async {
logout(context);
},
),
],
),
),
],
),
),
),
),
);
}
}