handelled the left bar employee names
This commit is contained in:
parent
48255f0d72
commit
70943aad01
@ -1,6 +1,8 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:marco/helpers/services/storage/local_storage.dart';
|
import 'package:marco/helpers/services/storage/local_storage.dart';
|
||||||
|
import 'package:marco/controller/permission_controller.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
class AuthService {
|
class AuthService {
|
||||||
static bool isLoggedIn = false;
|
static bool isLoggedIn = false;
|
||||||
@ -18,7 +20,7 @@ class AuthService {
|
|||||||
|
|
||||||
// Parse the response to get the JWT and refresh tokens
|
// Parse the response to get the JWT and refresh tokens
|
||||||
final responseData = jsonDecode(response.body);
|
final responseData = jsonDecode(response.body);
|
||||||
|
|
||||||
// Adjusted for the actual response structure
|
// Adjusted for the actual response structure
|
||||||
final jwtToken = responseData['data']['token']; // Ensure this matches your actual response
|
final jwtToken = responseData['data']['token']; // Ensure this matches your actual response
|
||||||
|
|
||||||
@ -35,7 +37,7 @@ class AuthService {
|
|||||||
|
|
||||||
// Save the login state in local storage
|
// Save the login state in local storage
|
||||||
await LocalStorage.setLoggedInUser(true);
|
await LocalStorage.setLoggedInUser(true);
|
||||||
|
Get.put(PermissionController());
|
||||||
// Return null to indicate success
|
// Return null to indicate success
|
||||||
return null;
|
return null;
|
||||||
} else if (response.statusCode == 401) {
|
} else if (response.statusCode == 401) {
|
||||||
|
@ -11,7 +11,6 @@ import 'package:marco/helpers/theme/theme_customizer.dart';
|
|||||||
import 'package:marco/routes.dart';
|
import 'package:marco/routes.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:url_strategy/url_strategy.dart';
|
import 'package:url_strategy/url_strategy.dart';
|
||||||
import 'package:marco/controller/permission_controller.dart';
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
setPathUrlStrategy();
|
setPathUrlStrategy();
|
||||||
@ -19,7 +18,6 @@ Future<void> main() async {
|
|||||||
await LocalStorage.init();
|
await LocalStorage.init();
|
||||||
AppStyle.init();
|
AppStyle.init();
|
||||||
await ThemeCustomizer.init();
|
await ThemeCustomizer.init();
|
||||||
Get.put(PermissionController());
|
|
||||||
runApp(ChangeNotifierProvider<AppNotifier>(
|
runApp(ChangeNotifierProvider<AppNotifier>(
|
||||||
create: (context) => AppNotifier(),
|
create: (context) => AppNotifier(),
|
||||||
child: MyApp(),
|
child: MyApp(),
|
||||||
|
@ -56,7 +56,13 @@ class _LeftBarState extends State<LeftBar>
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
employeeInfo = LocalStorage.getEmployeeInfo();
|
_loadEmployeeInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _loadEmployeeInfo() {
|
||||||
|
setState(() {
|
||||||
|
employeeInfo = LocalStorage.getEmployeeInfo();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -125,42 +131,46 @@ class _LeftBarState extends State<LeftBar>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget userInfoSection() {
|
Widget userInfoSection() {
|
||||||
return Padding(
|
if (employeeInfo == null) {
|
||||||
padding: MySpacing.fromLTRB(16, 8, 16, 8),
|
return Center(child: CircularProgressIndicator()); // Show loading indicator if employeeInfo is not yet loaded.
|
||||||
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),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
Widget labelWidget(String label) {
|
||||||
return isCondensed
|
return isCondensed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user