Intégration fonctionnalites V1
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../api/api_endpoints.dart';
|
||||
import '../api/api_response.dart';
|
||||
import '../config/app_config.dart';
|
||||
import 'server_time.dart';
|
||||
|
||||
/// Synchronise le fuseau horaire applicatif avec l'API (`/health`).
|
||||
Future<void> syncServerTimezone() async {
|
||||
try {
|
||||
final client = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: kApiBaseUrl,
|
||||
connectTimeout: const Duration(seconds: 5),
|
||||
receiveTimeout: const Duration(seconds: 5),
|
||||
headers: {'Accept': 'application/json'},
|
||||
),
|
||||
);
|
||||
|
||||
final response = await client.get(ApiEndpoints.health);
|
||||
final timezone = ApiResponse.payload(response.data)['timezone'];
|
||||
|
||||
if (timezone is String && timezone.isNotEmpty) {
|
||||
ServerTime.setTimezone(timezone);
|
||||
}
|
||||
} catch (_) {
|
||||
// Conserve le fuseau par défaut (Europe/Paris).
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user