Compare commits
2 Commits
c21384fb92
...
422ec9a6e1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
422ec9a6e1 | ||
|
|
d93c603573 |
@ -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/technician_to_invMaster.dart';
|
||||||
import 'screens/admin/product_request/invMaster_to_invMaster.dart';
|
import 'screens/admin/product_request/invMaster_to_invMaster.dart';
|
||||||
import 'screens/admin/product_request/product_request_form.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 'routes/slide_route.dart';
|
||||||
import 'package:inventory_system/services/api_service.dart';
|
import 'package:inventory_system/services/api_service.dart';
|
||||||
|
|
||||||
@ -111,6 +112,9 @@ class InventorySystemApp extends StatelessWidget {
|
|||||||
case '/scan-user':
|
case '/scan-user':
|
||||||
page = const ScanUserScreen();
|
page = const ScanUserScreen();
|
||||||
break;
|
break;
|
||||||
|
case '/profile':
|
||||||
|
page = const ProfileScreen();
|
||||||
|
break;
|
||||||
case '/item_movement_all':
|
case '/item_movement_all':
|
||||||
page = const ItemMovementAllScreen();
|
page = const ItemMovementAllScreen();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -328,7 +328,7 @@ class _ItemScreenState extends State<ItemScreen> {
|
|||||||
extentRatio: 0.45,
|
extentRatio: 0.45,
|
||||||
children: [
|
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) => 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(
|
child: Container(
|
||||||
|
|||||||
@ -246,42 +246,47 @@ class _ManufacturerScreenState extends State<ManufacturerScreen> {
|
|||||||
final name = manufacturer['manufacturerName'] ?? 'No Name';
|
final name = manufacturer['manufacturerName'] ?? 'No Name';
|
||||||
final id = manufacturer['manufacturerId'];
|
final id = manufacturer['manufacturerId'];
|
||||||
|
|
||||||
return Slidable(
|
return Padding(
|
||||||
key: Key(id.toString()),
|
padding: const EdgeInsets.only(bottom: 12),
|
||||||
endActionPane: ActionPane(
|
child: Slidable(
|
||||||
motion: const StretchMotion(),
|
key: Key(id.toString()),
|
||||||
children: [
|
endActionPane: ActionPane(
|
||||||
SlidableAction(
|
motion: const StretchMotion(),
|
||||||
onPressed: (context) => _showFormDialog(manufacturer: manufacturer),
|
children: [
|
||||||
backgroundColor: Colors.blue,
|
SlidableAction(
|
||||||
foregroundColor: Colors.white,
|
onPressed: (context) => _showFormDialog(manufacturer: manufacturer),
|
||||||
icon: Icons.edit,
|
backgroundColor: Colors.blue,
|
||||||
label: 'Edit',
|
foregroundColor: Colors.white,
|
||||||
),
|
icon: Icons.edit,
|
||||||
SlidableAction(
|
label: 'Edit',
|
||||||
onPressed: (context) => _confirmDelete(id, name),
|
),
|
||||||
backgroundColor: Colors.red,
|
SlidableAction(
|
||||||
foregroundColor: Colors.white,
|
onPressed: (context) => _confirmDelete(id, name),
|
||||||
icon: Icons.delete,
|
backgroundColor: Colors.red,
|
||||||
label: 'Delete',
|
foregroundColor: Colors.white,
|
||||||
),
|
icon: Icons.delete,
|
||||||
],
|
label: 'Delete',
|
||||||
),
|
borderRadius: const BorderRadius.horizontal(
|
||||||
child: Card(
|
right: Radius.circular(16)),
|
||||||
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),
|
|
||||||
),
|
),
|
||||||
child: ListTile(
|
child: Card(
|
||||||
title: Text(
|
margin: EdgeInsets.zero,
|
||||||
name,
|
color: Colors.white,
|
||||||
style: const TextStyle(
|
elevation: 1,
|
||||||
fontSize: 16,
|
shape: RoundedRectangleBorder(
|
||||||
fontWeight: FontWeight.w600,
|
borderRadius: BorderRadius.circular(16),
|
||||||
color: Colors.black87,
|
side: BorderSide(color: Colors.grey.shade300, width: 1),
|
||||||
|
),
|
||||||
|
child: ListTile(
|
||||||
|
title: Text(
|
||||||
|
name,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Colors.black87,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -249,6 +249,7 @@ class _ProductScreenState extends State<ProductScreen> {
|
|||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
label: 'Delete',
|
label: 'Delete',
|
||||||
icon: Icons.delete,
|
icon: Icons.delete,
|
||||||
|
borderRadius: const BorderRadius.horizontal(right: Radius.circular(16)),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@ -186,59 +186,64 @@ class _StationScreenState extends State<StationScreen> {
|
|||||||
itemCount: _filteredStations.length,
|
itemCount: _filteredStations.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final station = _filteredStations[index];
|
final station = _filteredStations[index];
|
||||||
return Slidable(
|
return Padding(
|
||||||
key: Key(station['stationId'].toString()),
|
padding: const EdgeInsets.only(bottom: 12),
|
||||||
endActionPane: ActionPane(
|
child: Slidable(
|
||||||
motion: const StretchMotion(),
|
key: Key(station['stationId'].toString()),
|
||||||
children: [
|
endActionPane: ActionPane(
|
||||||
SlidableAction(
|
motion: const StretchMotion(),
|
||||||
onPressed: (context) {
|
children: [
|
||||||
Navigator.push(
|
SlidableAction(
|
||||||
context,
|
onPressed: (context) {
|
||||||
MaterialPageRoute(
|
Navigator.push(
|
||||||
builder: (context) =>
|
context,
|
||||||
StationFormScreen(station: station)),
|
MaterialPageRoute(
|
||||||
).then((_) => _fetchStations());
|
builder: (context) =>
|
||||||
},
|
StationFormScreen(station: station)),
|
||||||
backgroundColor: Colors.blue,
|
).then((_) => _fetchStations());
|
||||||
foregroundColor: Colors.white,
|
},
|
||||||
icon: Icons.edit,
|
backgroundColor: Colors.blue,
|
||||||
label: 'Edit',
|
foregroundColor: Colors.white,
|
||||||
),
|
icon: Icons.edit,
|
||||||
SlidableAction(
|
label: 'Edit',
|
||||||
onPressed: (context) => _confirmDelete(
|
|
||||||
station['stationId'],
|
|
||||||
station['stationName'],
|
|
||||||
),
|
),
|
||||||
backgroundColor: Colors.red,
|
SlidableAction(
|
||||||
foregroundColor: Colors.white,
|
onPressed: (context) => _confirmDelete(
|
||||||
icon: Icons.delete,
|
station['stationId'],
|
||||||
label: 'Delete',
|
station['stationName'],
|
||||||
),
|
),
|
||||||
],
|
backgroundColor: Colors.red,
|
||||||
),
|
foregroundColor: Colors.white,
|
||||||
child: Card(
|
icon: Icons.delete,
|
||||||
margin: const EdgeInsets.only(bottom: 12),
|
label: 'Delete',
|
||||||
color: Colors.white,
|
borderRadius: const BorderRadius.horizontal(
|
||||||
elevation: 1,
|
right: Radius.circular(16)),
|
||||||
shape: RoundedRectangleBorder(
|
),
|
||||||
borderRadius: BorderRadius.circular(16),
|
],
|
||||||
side: BorderSide(color: Colors.grey.shade300),
|
|
||||||
),
|
),
|
||||||
child: ListTile(
|
child: Card(
|
||||||
contentPadding: const EdgeInsets.symmetric(
|
margin: EdgeInsets.zero,
|
||||||
vertical: 8,
|
color: Colors.white,
|
||||||
horizontal: 16),
|
elevation: 1,
|
||||||
title: Text(
|
shape: RoundedRectangleBorder(
|
||||||
station['stationName'] ?? 'No Name',
|
borderRadius: BorderRadius.circular(16),
|
||||||
style: const TextStyle(
|
side: BorderSide(color: Colors.grey.shade300),
|
||||||
fontSize: 16,
|
),
|
||||||
fontWeight: FontWeight.w600,
|
child: ListTile(
|
||||||
color: Colors.black87,
|
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'),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -52,6 +52,16 @@ class BottomNavBar extends StatelessWidget {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (index == 2) {
|
||||||
|
final currentRoute = ModalRoute.of(context)?.settings.name;
|
||||||
|
const profileRoute = '/profile';
|
||||||
|
|
||||||
|
if (currentRoute != profileRoute) {
|
||||||
|
Navigator.pushNamed(context, profileRoute);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
onItemTapped(index);
|
onItemTapped(index);
|
||||||
},
|
},
|
||||||
backgroundColor: Colors.blue[800],
|
backgroundColor: Colors.blue[800],
|
||||||
|
|||||||
@ -14,6 +14,7 @@ enum AppScreen {
|
|||||||
productRequestUser,
|
productRequestUser,
|
||||||
itemMovementUser,
|
itemMovementUser,
|
||||||
scan,
|
scan,
|
||||||
|
profile,
|
||||||
}
|
}
|
||||||
|
|
||||||
class NavBar extends StatelessWidget {
|
class NavBar extends StatelessWidget {
|
||||||
|
|||||||
162
lib/screens/profile/profile_screen.dart
Normal file
162
lib/screens/profile/profile_screen.dart
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:inventory_system/screens/bottom_nav_bar.dart';
|
||||||
|
import 'package:inventory_system/screens/title_bar.dart';
|
||||||
|
import 'package:inventory_system/services/auth_service.dart';
|
||||||
|
import 'package:inventory_system/screens/nav_bar.dart';
|
||||||
|
import 'package:inventory_system/services/session_manager.dart';
|
||||||
|
|
||||||
|
class ProfileScreen extends StatefulWidget {
|
||||||
|
const ProfileScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ProfileScreen> createState() => _ProfileScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ProfileScreenState extends State<ProfileScreen> {
|
||||||
|
final AuthService _authService = AuthService();
|
||||||
|
late Future<Map<String, dynamic>> _userProfileFuture;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_userProfileFuture = _authService.fetchUserProfile();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final isAdmin = SessionManager.instance.currentUser?['isAdmin'] ?? false;
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: const Color(0xFFF5F5F7),
|
||||||
|
appBar: const TitleBar(title: 'Profile'),
|
||||||
|
drawer: NavBar(isAdmin: isAdmin, selectedScreen: AppScreen.profile),
|
||||||
|
body: FutureBuilder<Map<String, dynamic>>(
|
||||||
|
future: _userProfileFuture,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
if (snapshot.hasError) {
|
||||||
|
return Center(child: Text('Error: ${snapshot.error}'));
|
||||||
|
}
|
||||||
|
|
||||||
|
final data = snapshot.data;
|
||||||
|
if (data == null || data['success'] != true) {
|
||||||
|
return Center(child: Text(data?['message'] ?? 'Failed to load profile'));
|
||||||
|
}
|
||||||
|
|
||||||
|
final userInfo = data['data'];
|
||||||
|
|
||||||
|
return SingleChildScrollView(
|
||||||
|
padding: const EdgeInsets.all(24.0),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
// Avatar
|
||||||
|
Container(
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withOpacity(0.1),
|
||||||
|
blurRadius: 10,
|
||||||
|
offset: const Offset(0, 5),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: const Icon(Icons.person, size: 60, color: Colors.grey),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 30),
|
||||||
|
|
||||||
|
_buildInfoCard(userInfo),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
bottomNavigationBar: BottomNavBar(
|
||||||
|
selectedIndex: 2,
|
||||||
|
onItemTapped: (index) {
|
||||||
|
// Handled by BottomNavBar internal logic
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildInfoCard(Map<String, dynamic> user) {
|
||||||
|
final email = user['email'] ?? 'N/A';
|
||||||
|
final company = user['company'] ?? 'N/A';
|
||||||
|
final departmentObj = user['department'];
|
||||||
|
String deptName = 'N/A';
|
||||||
|
if (departmentObj != null) {
|
||||||
|
deptName = departmentObj['departmentName'] ?? 'N/A';
|
||||||
|
}
|
||||||
|
final roles = user['role'] as List<dynamic>?;
|
||||||
|
final roleStr = roles?.join(', ') ?? 'N/A';
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
width: double.infinity,
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withOpacity(0.05),
|
||||||
|
blurRadius: 15,
|
||||||
|
offset: const Offset(0, 5),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
_buildInfoRow('Email', email, Icons.email_outlined),
|
||||||
|
const Divider(height: 32),
|
||||||
|
_buildInfoRow('Company', company, Icons.business_outlined),
|
||||||
|
const Divider(height: 32),
|
||||||
|
_buildInfoRow('Department', deptName, Icons.meeting_room_outlined),
|
||||||
|
const Divider(height: 32),
|
||||||
|
_buildInfoRow('Role', roleStr, Icons.admin_panel_settings_outlined),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildInfoRow(String label, String value, IconData icon) {
|
||||||
|
return Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Icon(icon, color: Colors.blue.shade700, size: 24),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
label,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Colors.grey.shade500,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text(
|
||||||
|
value,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
color: Colors.black87,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -50,6 +50,39 @@ class AuthService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Map<String, dynamic>> 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<String, dynamic>? 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<Map<String, dynamic>> _fetchLdapUserDetails(String sessionCookie, String username) async {
|
Future<Map<String, dynamic>> _fetchLdapUserDetails(String sessionCookie, String username) async {
|
||||||
final Uri userInfoUri = Uri.parse('${ApiService.baseUrl}/IdentityAPI/GetUserInformation');
|
final Uri userInfoUri = Uri.parse('${ApiService.baseUrl}/IdentityAPI/GetUserInformation');
|
||||||
final headers = {'Cookie': sessionCookie};
|
final headers = {'Cookie': sessionCookie};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user