fix
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../../core/di/providers.dart';
|
||||
import '../../../../core/services/print_service.dart';
|
||||
import '../../../../core/storage/secure_storage.dart';
|
||||
import '../../../../core/utils/text_utils.dart';
|
||||
import '../../../users/domain/entities/user_entity.dart';
|
||||
import '../../data/models/create_product_warehouse_request.dart';
|
||||
@@ -55,6 +56,9 @@ class _ProductDetailPageState extends ConsumerState<ProductDetailPage> {
|
||||
// Load users from Hive (no API call)
|
||||
await ref.read(usersProvider.notifier).getUsers();
|
||||
|
||||
// Auto-select warehouse user based on stored email
|
||||
await _autoSelectWarehouseUser();
|
||||
|
||||
await ref.read(productDetailProvider(_providerKey).notifier).loadProductDetail(
|
||||
widget.warehouseId,
|
||||
widget.productId,
|
||||
@@ -82,6 +86,43 @@ class _ProductDetailPageState extends ConsumerState<ProductDetailPage> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Auto-select warehouse user based on stored email from login
|
||||
Future<void> _autoSelectWarehouseUser() async {
|
||||
try {
|
||||
// Get stored email from secure storage
|
||||
final secureStorage = SecureStorage();
|
||||
final storedEmail = await secureStorage.getEmail();
|
||||
|
||||
if (storedEmail == null || storedEmail.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
print(storedEmail);
|
||||
|
||||
// Get all warehouse users
|
||||
final warehouseUsers = ref.read(usersListProvider)
|
||||
.where((user) => user.isWareHouseUser)
|
||||
.toList();
|
||||
|
||||
// Find user with matching email
|
||||
final matchingUsers = warehouseUsers
|
||||
.where((user) => user.email.toLowerCase() == storedEmail.toLowerCase())
|
||||
.toList();
|
||||
|
||||
final matchingUser = matchingUsers.isNotEmpty ? matchingUsers.first : null;
|
||||
|
||||
// Set selected warehouse user only if a match is found
|
||||
if (matchingUser != null && mounted) {
|
||||
setState(() {
|
||||
_selectedWarehouseUser = matchingUser;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// Silently fail - user can still manually select
|
||||
debugPrint('Error auto-selecting warehouse user: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onRefresh() async {
|
||||
// await ref.read(productDetailProvider(_providerKey).notifier).refreshProductDetail(
|
||||
// widget.warehouseId,
|
||||
@@ -476,7 +517,7 @@ class _ProductDetailPageState extends ConsumerState<ProductDetailPage> {
|
||||
|
||||
// Get responsible user name
|
||||
final responsibleName = '${_selectedWarehouseUser!.name} ${_selectedWarehouseUser!.firstName}';
|
||||
|
||||
final receiverName = '${_selectedEmployee!.name} ${_selectedEmployee!.firstName}';
|
||||
// Generate barcode data (using product code or product ID)
|
||||
final barcodeData = stage.productCode.isNotEmpty
|
||||
? stage.productCode
|
||||
@@ -495,6 +536,7 @@ class _ProductDetailPageState extends ConsumerState<ProductDetailPage> {
|
||||
issuedKg: finalIssuedKg,
|
||||
issuedPcs: finalIssuedPcs,
|
||||
responsibleName: responsibleName,
|
||||
receiverName: receiverName,
|
||||
barcodeData: barcodeData,
|
||||
);
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user