From a8187500acb91d91f9646af8149b90354ca0feed Mon Sep 17 00:00:00 2001 From: Lukas <35173609+PHPLukaas@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:46:08 +0100 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9E=95:=20Added=20flutter=5Fdotenv=20to?= =?UTF-8?q?=20pubspec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app_student/pubspec.lock | 8 ++++++++ frontend/app_student/pubspec.yaml | 1 + 2 files changed, 9 insertions(+) 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..a59001b 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: From 2afff6014472e15c66eeb5fa2cb2b5f9029adb5d Mon Sep 17 00:00:00 2001 From: Lukas <35173609+PHPLukaas@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:52:37 +0100 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=94=90:=20Add=20environnement=20varia?= =?UTF-8?q?bles=20to=20app?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app_student/.gitignore | 6 +++++- frontend/app_student/lib/config/dev_config.dart | 4 +++- frontend/app_student/lib/config/prod_config.dart | 4 +++- frontend/app_student/lib/main_dev.dart | 4 +++- 4 files changed, 14 insertions(+), 4 deletions(-) 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/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(), From b750abd107ad83f051475b3287276a4472b9548e Mon Sep 17 00:00:00 2001 From: Lukas <35173609+PHPLukaas@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:52:52 +0100 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=8D=B1:=20Added=20.env=20to=20pubspec?= =?UTF-8?q?=20assets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app_student/pubspec.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/app_student/pubspec.yaml b/frontend/app_student/pubspec.yaml index a59001b..5195719 100644 --- a/frontend/app_student/pubspec.yaml +++ b/frontend/app_student/pubspec.yaml @@ -77,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 From d23daf1b07a2dd5e0dfdc92179c05026fff073e2 Mon Sep 17 00:00:00 2001 From: Lukas <35173609+PHPLukaas@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:54:36 +0100 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=93=9D:=20Updated=20frontend=20README?= =?UTF-8?q?=20with=20env=20vars?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app_student/README.md | 7 +++++++ 1 file changed, 7 insertions(+) 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. From e2f3943aefadeb517a2e4a556940ffa5afaf45cf Mon Sep 17 00:00:00 2001 From: Lukas <35173609+PHPLukaas@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:59:25 +0100 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=94=A7:=20Sample=20env=20file=20for?= =?UTF-8?q?=20frontend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app_student/.env.dist | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 frontend/app_student/.env.dist 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