From 70943aad0189e48dafc6351c5c19cb2444fcf40c Mon Sep 17 00:00:00 2001 From: Vaibhav Surve Date: Sat, 3 May 2025 12:08:25 +0530 Subject: [PATCH] handelled the left bar employee names --- lib/helpers/services/auth_service.dart | 6 +- lib/main.dart | 2 - lib/view/layouts/left_bar.dart | 82 +++++++++++++++----------- 3 files changed, 50 insertions(+), 40 deletions(-) diff --git a/lib/helpers/services/auth_service.dart b/lib/helpers/services/auth_service.dart index fde383e..b48e3c1 100644 --- a/lib/helpers/services/auth_service.dart +++ b/lib/helpers/services/auth_service.dart @@ -1,6 +1,8 @@ import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:marco/helpers/services/storage/local_storage.dart'; +import 'package:marco/controller/permission_controller.dart'; +import 'package:get/get.dart'; class AuthService { static bool isLoggedIn = false; @@ -18,7 +20,7 @@ class AuthService { // Parse the response to get the JWT and refresh tokens final responseData = jsonDecode(response.body); - + // Adjusted for the actual response structure final jwtToken = responseData['data']['token']; // Ensure this matches your actual response @@ -35,7 +37,7 @@ class AuthService { // Save the login state in local storage await LocalStorage.setLoggedInUser(true); - + Get.put(PermissionController()); // Return null to indicate success return null; } else if (response.statusCode == 401) { diff --git a/lib/main.dart b/lib/main.dart index e4df27f..99a9be4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,7 +11,6 @@ import 'package:marco/helpers/theme/theme_customizer.dart'; import 'package:marco/routes.dart'; import 'package:provider/provider.dart'; import 'package:url_strategy/url_strategy.dart'; -import 'package:marco/controller/permission_controller.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); setPathUrlStrategy(); @@ -19,7 +18,6 @@ Future main() async { await LocalStorage.init(); AppStyle.init(); await ThemeCustomizer.init(); - Get.put(PermissionController()); runApp(ChangeNotifierProvider( create: (context) => AppNotifier(), child: MyApp(), diff --git a/lib/view/layouts/left_bar.dart b/lib/view/layouts/left_bar.dart index 67006e3..b98ed62 100644 --- a/lib/view/layouts/left_bar.dart +++ b/lib/view/layouts/left_bar.dart @@ -56,7 +56,13 @@ class _LeftBarState extends State @override void initState() { super.initState(); - employeeInfo = LocalStorage.getEmployeeInfo(); + _loadEmployeeInfo(); + } + + void _loadEmployeeInfo() { + setState(() { + employeeInfo = LocalStorage.getEmployeeInfo(); + }); } @override @@ -125,42 +131,46 @@ class _LeftBarState extends State ); } - Widget userInfoSection() { - return Padding( - padding: MySpacing.fromLTRB(16, 8, 16, 8), - child: Row( - children: [ - Avatar( - firstName: employeeInfo?.firstName ?? 'First', - lastName: employeeInfo?.lastName ?? 'Name', - ), - MySpacing.width(16), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - MyText.labelSmall( - "${employeeInfo?.firstName ?? 'First Name'} ${employeeInfo?.lastName ?? 'Last Name'}", - fontWeight: 600, - muted: true, - ), - ], - ), - ), - MyContainer( - onTap: () { - Get.offNamed('/auth/login'); - }, - color: leftBarTheme.activeItemBackground, - paddingAll: 8, - child: Icon(LucideIcons.log_out, - size: 16, color: leftBarTheme.activeItemColor), - ) - ], - ), - ); + Widget userInfoSection() { + if (employeeInfo == null) { + return Center(child: CircularProgressIndicator()); // Show loading indicator if employeeInfo is not yet loaded. } + + return Padding( + padding: MySpacing.fromLTRB(16, 8, 16, 8), + child: Row( + children: [ + Avatar( + firstName: employeeInfo?.firstName ?? 'First', + lastName: employeeInfo?.lastName ?? 'Name', + ), + MySpacing.width(16), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + MyText.labelSmall( + "${employeeInfo?.firstName ?? 'First Name'} ${employeeInfo?.lastName ?? 'Last Name'}", + fontWeight: 600, + muted: true, + ), + ], + ), + ), + MyContainer( + onTap: () { + Get.offNamed('/auth/login'); + }, + color: leftBarTheme.activeItemBackground, + paddingAll: 8, + child: Icon(LucideIcons.log_out, + size: 16, color: leftBarTheme.activeItemColor), + ) + ], + ), + ); +} Widget labelWidget(String label) { return isCondensed