Évite Uri.base.origin sur flutter run -d chrome qui visait le serveur de dev. Co-authored-by: Cursor <cursoragent@cursor.com>
28 lines
1.0 KiB
Dart
28 lines
1.0 KiB
Dart
import 'package:flutter/foundation.dart' show kDebugMode, kIsWeb;
|
||
|
||
class Env {
|
||
/// Base URL de l’API (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 l’IDE / `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';
|
||
}
|