store current user id

This commit is contained in:
2025-11-03 20:59:51 +07:00
parent 2a6ec8f6b8
commit 9df4b79a66
6 changed files with 123 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../../core/di/providers.dart';
import '../../../../core/router/app_router.dart';
import '../../../../core/storage/secure_storage.dart';
import '../widgets/warehouse_card.dart';
import '../widgets/warehouse_drawer.dart';
@@ -28,12 +29,34 @@ class _WarehouseSelectionPageState
void initState() {
super.initState();
// Load warehouses when page is first created
Future.microtask(() {
Future.microtask(() async {
ref.read(warehouseProvider.notifier).loadWarehouses();
// Users are automatically loaded from local storage by UsersNotifier
// Get current user and store user ID
await _getCurrentUserAndStoreId();
});
}
/// Get current user from API and store user ID in secure storage
Future<void> _getCurrentUserAndStoreId() async {
try {
final secureStorage = SecureStorage();
final usersDataSource = ref.read(usersRemoteDataSourceProvider);
// Call API to get current user
final currentUser = await usersDataSource.getCurrentUser();
// Store the current user ID
await secureStorage.saveCurrentUserId(currentUser.id);
debugPrint('Current user ID stored: ${currentUser.id}');
} catch (e) {
// Silently fail - this is not critical
debugPrint('Error getting current user: $e');
}
}
@override
Widget build(BuildContext context) {
// Watch warehouse state