Julien Martin 919148fa75 fix(front): en mode debug sans API_BASE_URL, cibler le back prod (web inclus)
Évite Uri.base.origin sur flutter run -d chrome qui visait le serveur de dev.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-13 17:52:54 +02:00

28 lines
1.0 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/foundation.dart' show kDebugMode, kIsWeb;
class Env {
/// Base URL de lAPI (sans `/api/v1`).
///
/// - **`API_BASE_URL` en `--dart-define`** : prioritaire (back local, staging, etc.).
/// - **Mode debug sans define** : toujours **`https://app.ptits-pas.fr`** (web inclus) pour
/// pointer sur le back de prod depuis lIDE / `flutter run`.
/// - **Web release / profile sans define** : [Uri.base.origin] (même hôte que la page déployée).
/// - **Mobile release / profile sans define** : `https://app.ptits-pas.fr`.
static String get apiBaseUrl {
const fromEnv = String.fromEnvironment('API_BASE_URL');
if (fromEnv.isNotEmpty) {
return fromEnv;
}
if (kDebugMode) {
return 'https://app.ptits-pas.fr';
}
if (kIsWeb) {
return Uri.base.origin;
}
return 'https://app.ptits-pas.fr';
}
/// Construit une URL vers l'API v1 à partir d'un chemin (commençant par '/')
static String apiV1(String path) => '${apiBaseUrl}/api/v1$path';
}