fix api
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../constants/environment_config.dart';
|
||||
import '../database/hive_service.dart';
|
||||
import '../database/models/app_settings.dart';
|
||||
import '../database/providers/database_providers.dart';
|
||||
@@ -267,15 +268,33 @@ class AppConfiguration extends _$AppConfiguration {
|
||||
final buildMode = ref.watch(appBuildModeProvider);
|
||||
|
||||
return {
|
||||
'apiTimeout': 30000, // 30 seconds
|
||||
// Environment-specific API configuration
|
||||
'environment': EnvironmentConfig.currentEnvironment.name,
|
||||
'baseUrl': EnvironmentConfig.baseUrl,
|
||||
'apiPath': EnvironmentConfig.apiPath,
|
||||
'fullBaseUrl': EnvironmentConfig.fullBaseUrl,
|
||||
'connectTimeout': EnvironmentConfig.connectTimeout,
|
||||
'receiveTimeout': EnvironmentConfig.receiveTimeout,
|
||||
'sendTimeout': EnvironmentConfig.sendTimeout,
|
||||
'maxRetries': EnvironmentConfig.maxRetries,
|
||||
'retryDelay': EnvironmentConfig.retryDelay.inMilliseconds,
|
||||
|
||||
// Environment-specific logging
|
||||
'enableLogging': EnvironmentConfig.enableLogging,
|
||||
'enableDetailedLogging': EnvironmentConfig.enableDetailedLogging,
|
||||
'enableCertificatePinning': EnvironmentConfig.enableCertificatePinning,
|
||||
'logLevel': EnvironmentConfig.enableDetailedLogging ? 'verbose' : 'error',
|
||||
|
||||
// General configuration
|
||||
'cacheTimeout': 3600000, // 1 hour in milliseconds
|
||||
'maxRetries': 3,
|
||||
'retryDelay': 1000, // 1 second
|
||||
'enableLogging': buildMode == 'debug',
|
||||
'logLevel': buildMode == 'debug' ? 'verbose' : 'error',
|
||||
'maxCacheSize': 100 * 1024 * 1024, // 100MB
|
||||
'imageQuality': 85,
|
||||
'compressionEnabled': true,
|
||||
|
||||
// Environment flags
|
||||
'isDevelopment': EnvironmentConfig.isDevelopment,
|
||||
'isStaging': EnvironmentConfig.isStaging,
|
||||
'isProduction': EnvironmentConfig.isProduction,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -345,4 +364,69 @@ class ErrorTracker extends _$ErrorTracker {
|
||||
List<Map<String, dynamic>> getRecentErrors({int count = 10}) {
|
||||
return state.reversed.take(count).toList();
|
||||
}
|
||||
}
|
||||
|
||||
/// Environment debug information provider
|
||||
@riverpod
|
||||
Map<String, dynamic> environmentDebugInfo(EnvironmentDebugInfoRef ref) {
|
||||
return EnvironmentConfig.debugInfo;
|
||||
}
|
||||
|
||||
/// API connectivity test provider
|
||||
@riverpod
|
||||
class ApiConnectivityTest extends _$ApiConnectivityTest {
|
||||
@override
|
||||
Future<Map<String, dynamic>> build() async {
|
||||
return _testConnectivity();
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> _testConnectivity() async {
|
||||
try {
|
||||
debugPrint('🔍 Testing API connectivity to ${EnvironmentConfig.baseUrl}...');
|
||||
|
||||
final result = {
|
||||
'baseUrl': EnvironmentConfig.baseUrl,
|
||||
'fullBaseUrl': EnvironmentConfig.fullBaseUrl,
|
||||
'loginUrl': EnvironmentConfig.loginUrl,
|
||||
'environment': EnvironmentConfig.currentEnvironment.name,
|
||||
'timestamp': DateTime.now().toIso8601String(),
|
||||
'status': 'success',
|
||||
'message': 'Configuration loaded successfully',
|
||||
'endpoints': {
|
||||
'login': EnvironmentConfig.loginUrl,
|
||||
'register': EnvironmentConfig.registerUrl,
|
||||
'refresh': EnvironmentConfig.refreshUrl,
|
||||
'logout': EnvironmentConfig.logoutUrl,
|
||||
},
|
||||
'settings': {
|
||||
'connectTimeout': EnvironmentConfig.connectTimeout,
|
||||
'receiveTimeout': EnvironmentConfig.receiveTimeout,
|
||||
'sendTimeout': EnvironmentConfig.sendTimeout,
|
||||
'maxRetries': EnvironmentConfig.maxRetries,
|
||||
'retryDelay': EnvironmentConfig.retryDelay.inMilliseconds,
|
||||
'enableLogging': EnvironmentConfig.enableLogging,
|
||||
'enableDetailedLogging': EnvironmentConfig.enableDetailedLogging,
|
||||
}
|
||||
};
|
||||
|
||||
debugPrint('✅ API connectivity test completed successfully');
|
||||
return result;
|
||||
} catch (error, stackTrace) {
|
||||
debugPrint('❌ API connectivity test failed: $error');
|
||||
debugPrint('Stack trace: $stackTrace');
|
||||
|
||||
return {
|
||||
'status': 'error',
|
||||
'error': error.toString(),
|
||||
'timestamp': DateTime.now().toIso8601String(),
|
||||
'baseUrl': EnvironmentConfig.baseUrl,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Retry connectivity test
|
||||
Future<void> retry() async {
|
||||
state = const AsyncValue.loading();
|
||||
state = AsyncValue.data(await _testConnectivity());
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,25 @@ final isAppReadyProvider = AutoDisposeProvider<bool>.internal(
|
||||
);
|
||||
|
||||
typedef IsAppReadyRef = AutoDisposeProviderRef<bool>;
|
||||
String _$environmentDebugInfoHash() =>
|
||||
r'8a936abed2173bd1539eec64231e8d970ed7382a';
|
||||
|
||||
/// Environment debug information provider
|
||||
///
|
||||
/// Copied from [environmentDebugInfo].
|
||||
@ProviderFor(environmentDebugInfo)
|
||||
final environmentDebugInfoProvider =
|
||||
AutoDisposeProvider<Map<String, dynamic>>.internal(
|
||||
environmentDebugInfo,
|
||||
name: r'environmentDebugInfoProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$environmentDebugInfoHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef EnvironmentDebugInfoRef = AutoDisposeProviderRef<Map<String, dynamic>>;
|
||||
String _$appInitializationHash() => r'cdf86e2d6985c6dcee80f618bc032edf81011fc9';
|
||||
|
||||
/// App initialization provider
|
||||
@@ -142,7 +161,7 @@ final featureFlagsProvider =
|
||||
);
|
||||
|
||||
typedef _$FeatureFlags = AutoDisposeNotifier<Map<String, bool>>;
|
||||
String _$appConfigurationHash() => r'115fff1ac67a37ff620bbd15ea142a7211e9dc9c';
|
||||
String _$appConfigurationHash() => r'7699bbd57d15b91cd520a876454368e5b97342bd';
|
||||
|
||||
/// App configuration provider
|
||||
///
|
||||
@@ -196,5 +215,24 @@ final errorTrackerProvider = AutoDisposeNotifierProvider<ErrorTracker,
|
||||
);
|
||||
|
||||
typedef _$ErrorTracker = AutoDisposeNotifier<List<Map<String, dynamic>>>;
|
||||
String _$apiConnectivityTestHash() =>
|
||||
r'19c63d75d09ad8f95452afb1a409528fcdd5cbaa';
|
||||
|
||||
/// API connectivity test provider
|
||||
///
|
||||
/// Copied from [ApiConnectivityTest].
|
||||
@ProviderFor(ApiConnectivityTest)
|
||||
final apiConnectivityTestProvider = AutoDisposeAsyncNotifierProvider<
|
||||
ApiConnectivityTest, Map<String, dynamic>>.internal(
|
||||
ApiConnectivityTest.new,
|
||||
name: r'apiConnectivityTestProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$apiConnectivityTestHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$ApiConnectivityTest = AutoDisposeAsyncNotifier<Map<String, dynamic>>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
import '../network/auth_service_example.dart';
|
||||
import '../network/dio_client.dart';
|
||||
import '../network/network_info.dart';
|
||||
|
||||
@@ -48,4 +49,16 @@ final isConnectedProvider = FutureProvider<bool>((ref) async {
|
||||
final networkConnectionDetailsProvider = FutureProvider((ref) async {
|
||||
final networkInfo = ref.watch(networkInfoProvider) as NetworkInfoImpl;
|
||||
return await networkInfo.getConnectionDetails();
|
||||
});
|
||||
|
||||
/// Provider for AuthServiceExample - demonstrates localhost:3000 API usage
|
||||
final authServiceExampleProvider = Provider<AuthServiceExample>((ref) {
|
||||
final dioClient = ref.watch(dioClientProvider);
|
||||
return AuthServiceExample(dioClient);
|
||||
});
|
||||
|
||||
/// Provider for environment information debugging
|
||||
final environmentInfoProvider = Provider<Map<String, dynamic>>((ref) {
|
||||
final authService = ref.watch(authServiceExampleProvider);
|
||||
return authService.getEnvironmentInfo();
|
||||
});
|
||||
Reference in New Issue
Block a user