From d93c603573bf466c20a5447ade81a4935dfddf7b Mon Sep 17 00:00:00 2001 From: Aiman Hafiz <121177088+RoninBonin@users.noreply.github.com> Date: Mon, 15 Dec 2025 16:04:14 +0800 Subject: [PATCH] update to profile --- lib/main.dart | 4 + lib/screens/admin/item/item.dart | 2 +- .../admin/manufacturer/manufacturer.dart | 75 +++++++------ lib/screens/admin/product/product.dart | 1 + lib/screens/admin/station/station.dart | 105 +++++++++--------- lib/screens/bottom_nav_bar.dart | 10 ++ lib/screens/nav_bar.dart | 1 + lib/services/auth_service.dart | 33 ++++++ 8 files changed, 145 insertions(+), 86 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index c4dea22..3a20637 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -20,6 +20,7 @@ import 'screens/admin/item_movement/item_movement_station.dart'; import 'screens/admin/product_request/technician_to_invMaster.dart'; import 'screens/admin/product_request/invMaster_to_invMaster.dart'; import 'screens/admin/product_request/product_request_form.dart'; +import 'screens/profile/profile_screen.dart'; // Add this import import 'routes/slide_route.dart'; import 'package:inventory_system/services/api_service.dart'; @@ -111,6 +112,9 @@ class InventorySystemApp extends StatelessWidget { case '/scan-user': page = const ScanUserScreen(); break; + case '/profile': + page = const ProfileScreen(); + break; case '/item_movement_all': page = const ItemMovementAllScreen(); break; diff --git a/lib/screens/admin/item/item.dart b/lib/screens/admin/item/item.dart index 04e6c34..7bbab30 100644 --- a/lib/screens/admin/item/item.dart +++ b/lib/screens/admin/item/item.dart @@ -328,7 +328,7 @@ class _ItemScreenState extends State { extentRatio: 0.45, children: [ SlidableAction(onPressed: (context) => Navigator.push(context, MaterialPageRoute(builder: (context) => ItemFormScreen(item: item))).then((success) => {if(success == true) _fetchItems()}), backgroundColor: Colors.blue, foregroundColor: Colors.white, icon: Icons.edit, label: 'Edit'), - SlidableAction(onPressed: (context) => _confirmDelete(item['itemID'], item['productName']), backgroundColor: Colors.red, foregroundColor: Colors.white, icon: Icons.delete, label: 'Delete'), + SlidableAction(onPressed: (context) => _confirmDelete(item['itemID'], item['productName']), backgroundColor: Colors.red, foregroundColor: Colors.white, icon: Icons.delete, label: 'Delete', borderRadius: const BorderRadius.horizontal(right: Radius.circular(16))), ], ), child: Container( diff --git a/lib/screens/admin/manufacturer/manufacturer.dart b/lib/screens/admin/manufacturer/manufacturer.dart index 2b85535..234f6f7 100644 --- a/lib/screens/admin/manufacturer/manufacturer.dart +++ b/lib/screens/admin/manufacturer/manufacturer.dart @@ -246,42 +246,47 @@ class _ManufacturerScreenState extends State { final name = manufacturer['manufacturerName'] ?? 'No Name'; final id = manufacturer['manufacturerId']; - return Slidable( - key: Key(id.toString()), - endActionPane: ActionPane( - motion: const StretchMotion(), - children: [ - SlidableAction( - onPressed: (context) => _showFormDialog(manufacturer: manufacturer), - backgroundColor: Colors.blue, - foregroundColor: Colors.white, - icon: Icons.edit, - label: 'Edit', - ), - SlidableAction( - onPressed: (context) => _confirmDelete(id, name), - backgroundColor: Colors.red, - foregroundColor: Colors.white, - icon: Icons.delete, - label: 'Delete', - ), - ], - ), - child: Card( - margin: const EdgeInsets.only(bottom: 12), - color: Colors.white, - elevation: 1, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(16), - side: BorderSide(color: Colors.grey.shade300, width: 1), + return Padding( + padding: const EdgeInsets.only(bottom: 12), + child: Slidable( + key: Key(id.toString()), + endActionPane: ActionPane( + motion: const StretchMotion(), + children: [ + SlidableAction( + onPressed: (context) => _showFormDialog(manufacturer: manufacturer), + backgroundColor: Colors.blue, + foregroundColor: Colors.white, + icon: Icons.edit, + label: 'Edit', + ), + SlidableAction( + onPressed: (context) => _confirmDelete(id, name), + backgroundColor: Colors.red, + foregroundColor: Colors.white, + icon: Icons.delete, + label: 'Delete', + borderRadius: const BorderRadius.horizontal( + right: Radius.circular(16)), + ), + ], ), - child: ListTile( - title: Text( - name, - style: const TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - color: Colors.black87, + child: Card( + margin: EdgeInsets.zero, + color: Colors.white, + elevation: 1, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16), + side: BorderSide(color: Colors.grey.shade300, width: 1), + ), + child: ListTile( + title: Text( + name, + style: const TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: Colors.black87, + ), ), ), ), diff --git a/lib/screens/admin/product/product.dart b/lib/screens/admin/product/product.dart index 543b876..8132125 100644 --- a/lib/screens/admin/product/product.dart +++ b/lib/screens/admin/product/product.dart @@ -249,6 +249,7 @@ class _ProductScreenState extends State { foregroundColor: Colors.white, label: 'Delete', icon: Icons.delete, + borderRadius: const BorderRadius.horizontal(right: Radius.circular(16)), ), ], ), diff --git a/lib/screens/admin/station/station.dart b/lib/screens/admin/station/station.dart index 45706a9..64edc0c 100644 --- a/lib/screens/admin/station/station.dart +++ b/lib/screens/admin/station/station.dart @@ -186,59 +186,64 @@ class _StationScreenState extends State { itemCount: _filteredStations.length, itemBuilder: (context, index) { final station = _filteredStations[index]; - return Slidable( - key: Key(station['stationId'].toString()), - endActionPane: ActionPane( - motion: const StretchMotion(), - children: [ - SlidableAction( - onPressed: (context) { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => - StationFormScreen(station: station)), - ).then((_) => _fetchStations()); - }, - backgroundColor: Colors.blue, - foregroundColor: Colors.white, - icon: Icons.edit, - label: 'Edit', - ), - SlidableAction( - onPressed: (context) => _confirmDelete( - station['stationId'], - station['stationName'], + return Padding( + padding: const EdgeInsets.only(bottom: 12), + child: Slidable( + key: Key(station['stationId'].toString()), + endActionPane: ActionPane( + motion: const StretchMotion(), + children: [ + SlidableAction( + onPressed: (context) { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + StationFormScreen(station: station)), + ).then((_) => _fetchStations()); + }, + backgroundColor: Colors.blue, + foregroundColor: Colors.white, + icon: Icons.edit, + label: 'Edit', ), - backgroundColor: Colors.red, - foregroundColor: Colors.white, - icon: Icons.delete, - label: 'Delete', - ), - ], - ), - child: Card( - margin: const EdgeInsets.only(bottom: 12), - color: Colors.white, - elevation: 1, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(16), - side: BorderSide(color: Colors.grey.shade300), + SlidableAction( + onPressed: (context) => _confirmDelete( + station['stationId'], + station['stationName'], + ), + backgroundColor: Colors.red, + foregroundColor: Colors.white, + icon: Icons.delete, + label: 'Delete', + borderRadius: const BorderRadius.horizontal( + right: Radius.circular(16)), + ), + ], ), - child: ListTile( - contentPadding: const EdgeInsets.symmetric( - vertical: 8, - horizontal: 16), - title: Text( - station['stationName'] ?? 'No Name', - style: const TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - color: Colors.black87, - ), + child: Card( + margin: EdgeInsets.zero, + color: Colors.white, + elevation: 1, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16), + side: BorderSide(color: Colors.grey.shade300), + ), + child: ListTile( + contentPadding: const EdgeInsets.symmetric( + vertical: 8, + horizontal: 16), + title: Text( + station['stationName'] ?? 'No Name', + style: const TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: Colors.black87, + ), + ), + subtitle: Text( + station['departmentName'] ?? 'No Department'), ), - subtitle: Text( - station['departmentName'] ?? 'No Department'), ), ), ); diff --git a/lib/screens/bottom_nav_bar.dart b/lib/screens/bottom_nav_bar.dart index 0ede932..26a689c 100644 --- a/lib/screens/bottom_nav_bar.dart +++ b/lib/screens/bottom_nav_bar.dart @@ -52,6 +52,16 @@ class BottomNavBar extends StatelessWidget { return; } + if (index == 2) { + final currentRoute = ModalRoute.of(context)?.settings.name; + const profileRoute = '/profile'; + + if (currentRoute != profileRoute) { + Navigator.pushNamed(context, profileRoute); + } + return; + } + onItemTapped(index); }, backgroundColor: Colors.blue[800], diff --git a/lib/screens/nav_bar.dart b/lib/screens/nav_bar.dart index cc909b3..47c2d8a 100644 --- a/lib/screens/nav_bar.dart +++ b/lib/screens/nav_bar.dart @@ -14,6 +14,7 @@ enum AppScreen { productRequestUser, itemMovementUser, scan, + profile, } class NavBar extends StatelessWidget { diff --git a/lib/services/auth_service.dart b/lib/services/auth_service.dart index 5ed2ba1..27ad250 100644 --- a/lib/services/auth_service.dart +++ b/lib/services/auth_service.dart @@ -50,6 +50,39 @@ class AuthService { } } + Future> fetchUserProfile() async { + final String? sessionCookie = SessionManager.instance.getCookie(); + if (sessionCookie == null) { + return {'success': false, 'message': 'No active session found.'}; + } + + final Uri userInfoUri = Uri.parse('${ApiService.baseUrl}/IdentityAPI/GetUserInformation'); + final headers = {'Cookie': sessionCookie}; + + try { + final response = await http.post(userInfoUri, headers: headers); + + if (response.statusCode == 200) { + final userInfoResponse = jsonDecode(response.body); + final Map? userData = userInfoResponse['userInfo']; + + if (userData == null) { + return {'success': false, 'message': 'User profile data is missing from the API response.'}; + } + + return { + 'success': true, + 'data': userData // Return raw user data as requested for display + }; + } else { + return {'success': false, 'message': 'Failed to retrieve user profile. Status: ${response.statusCode}'}; + } + } catch (e) { + debugPrint('Error fetching user profile: $e'); + return {'success': false, 'message': 'Error fetching user details.'}; + } + } + Future> _fetchLdapUserDetails(String sessionCookie, String username) async { final Uri userInfoUri = Uri.parse('${ApiService.baseUrl}/IdentityAPI/GetUserInformation'); final headers = {'Cookie': sessionCookie};