diff --git a/frontend/app_student/.env.dist b/frontend/app_student/.env.dist new file mode 100644 index 0000000..4873f58 --- /dev/null +++ b/frontend/app_student/.env.dist @@ -0,0 +1,2 @@ +DEV_API_URL= +PROD_API_URL= \ No newline at end of file diff --git a/frontend/app_student/.gitignore b/frontend/app_student/.gitignore index 4dfa933..8049450 100644 --- a/frontend/app_student/.gitignore +++ b/frontend/app_student/.gitignore @@ -43,4 +43,8 @@ app.*.map.json /android/app/release # FVM Version Cache -.fvm/ \ No newline at end of file +.fvm/ + +# Env file +/.env +/.env.local \ No newline at end of file diff --git a/frontend/app_student/README.md b/frontend/app_student/README.md index 65bb4be..9164882 100644 --- a/frontend/app_student/README.md +++ b/frontend/app_student/README.md @@ -27,6 +27,13 @@ Avant de pousser votre code, assurez-vous de respecter les points suivants : - Exécutez `flutter analyze` pour détecter tout problème dans votre code. - Assurez-vous d'exécuter `pub get` pour installer toutes les dépendances du projet. +### Variables d'environnement + +Pour que l'application fonctionne correctement, vous devez définir les variables d'environnement suivantes dans un fichier `.env` à la racine du projet : + +- `API_URL_DEV`: URL de l'API de développement. +- `API_URL_PROD`: URL de l'API de production. + ## Contributions Les contributions des autres étudiants sont les bienvenues! N'hésitez pas à proposer des améliorations, des corrections de bugs ou de nouvelles fonctionnalités en soumettant des pull requests. diff --git a/frontend/app_student/lib/config/dev_config.dart b/frontend/app_student/lib/config/dev_config.dart index af2b236..0766185 100644 --- a/frontend/app_student/lib/config/dev_config.dart +++ b/frontend/app_student/lib/config/dev_config.dart @@ -1,6 +1,8 @@ +import 'package:flutter_dotenv/flutter_dotenv.dart'; + import 'config.dart'; class DevConfig extends Config { @override - String get apiUrl => 'https://api-dev.lukasvalois.com'; + String get apiUrl => dotenv.env['DEV_API_URL'] ?? 'http://localhost:8000'; } diff --git a/frontend/app_student/lib/config/prod_config.dart b/frontend/app_student/lib/config/prod_config.dart index 31e87e0..fbf9831 100644 --- a/frontend/app_student/lib/config/prod_config.dart +++ b/frontend/app_student/lib/config/prod_config.dart @@ -1,6 +1,8 @@ +import 'package:flutter_dotenv/flutter_dotenv.dart'; + import 'config.dart'; class ProdConfig extends Config { @override - String get apiUrl => 'https://api.lukasvalois.com'; + String get apiUrl => dotenv.env['PROD_API_URL'] ?? 'http://localhost:8000'; } diff --git a/frontend/app_student/lib/main_dev.dart b/frontend/app_student/lib/main_dev.dart index b5a41d2..c8b8bce 100644 --- a/frontend/app_student/lib/main_dev.dart +++ b/frontend/app_student/lib/main_dev.dart @@ -1,6 +1,7 @@ import 'package:app_student/config/dev_config.dart'; import 'package:app_student/routes.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:go_router/go_router.dart'; @@ -8,7 +9,8 @@ import 'package:provider/provider.dart'; import 'config/config.dart'; -void main() { +void main() async { + await dotenv.load(); runApp( Provider( create: (_) => DevConfig(), diff --git a/frontend/app_student/pubspec.lock b/frontend/app_student/pubspec.lock index f99adda..21eeab5 100644 --- a/frontend/app_student/pubspec.lock +++ b/frontend/app_student/pubspec.lock @@ -102,6 +102,14 @@ packages: url: "https://pub.dev" source: hosted version: "8.1.4" + flutter_dotenv: + dependency: "direct main" + description: + name: flutter_dotenv + sha256: "9357883bdd153ab78cbf9ffa07656e336b8bbb2b5a3ca596b0b27e119f7c7d77" + url: "https://pub.dev" + source: hosted + version: "5.1.0" flutter_lints: dependency: "direct dev" description: diff --git a/frontend/app_student/pubspec.yaml b/frontend/app_student/pubspec.yaml index 73c55d0..5195719 100644 --- a/frontend/app_student/pubspec.yaml +++ b/frontend/app_student/pubspec.yaml @@ -46,6 +46,7 @@ dependencies: flutter_localizations: sdk: flutter intl: any + flutter_dotenv: ^5.1.0 dev_dependencies: flutter_test: @@ -76,6 +77,7 @@ flutter: assets: - assets/images/ + - .env # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware