runable
This commit is contained in:
@@ -448,20 +448,20 @@ class ErrorHandlingExample extends ConsumerWidget {
|
||||
|
||||
void nonWidgetExample() {
|
||||
// If you need to access auth outside widgets (e.g., in services),
|
||||
// use the service locator directly:
|
||||
// you can pass WidgetRef as a parameter or use ProviderContainer:
|
||||
|
||||
// import 'package:retail/core/di/injection_container.dart';
|
||||
// import 'package:retail/features/auth/domain/repositories/auth_repository.dart';
|
||||
// Method 1: Pass WidgetRef as parameter
|
||||
// Future<void> myService(WidgetRef ref) async {
|
||||
// final authRepository = ref.read(authRepositoryProvider);
|
||||
// final isAuthenticated = await authRepository.isAuthenticated();
|
||||
// print('Is authenticated: $isAuthenticated');
|
||||
// }
|
||||
|
||||
// final authRepository = sl<AuthRepository>();
|
||||
//
|
||||
// // Check if authenticated
|
||||
// Method 2: Use ProviderContainer (for non-Flutter code)
|
||||
// final container = ProviderContainer();
|
||||
// final authRepository = container.read(authRepositoryProvider);
|
||||
// final isAuthenticated = await authRepository.isAuthenticated();
|
||||
//
|
||||
// // Get token
|
||||
// final token = await authRepository.getAccessToken();
|
||||
//
|
||||
// print('Token: $token');
|
||||
// container.dispose(); // Don't forget to dispose!
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
@@ -477,7 +477,9 @@ void tokenInjectionExample() {
|
||||
// You don't need to manually add the token - it's automatic!
|
||||
|
||||
// Example of making an API call after login:
|
||||
// final response = await sl<DioClient>().get('/api/products');
|
||||
// Using Riverpod:
|
||||
// final dioClient = ref.read(dioClientProvider);
|
||||
// final response = await dioClient.get('/api/products');
|
||||
//
|
||||
// The above request will automatically include:
|
||||
// Headers: {
|
||||
|
||||
Reference in New Issue
Block a user