Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/app env vars #38

Merged
merged 5 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/app_student/.env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DEV_API_URL=
PROD_API_URL=
6 changes: 5 additions & 1 deletion frontend/app_student/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ app.*.map.json
/android/app/release

# FVM Version Cache
.fvm/
.fvm/

# Env file
/.env
/.env.local
7 changes: 7 additions & 0 deletions frontend/app_student/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion frontend/app_student/lib/config/dev_config.dart
Original file line number Diff line number Diff line change
@@ -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';
}
4 changes: 3 additions & 1 deletion frontend/app_student/lib/config/prod_config.dart
Original file line number Diff line number Diff line change
@@ -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';
}
4 changes: 3 additions & 1 deletion frontend/app_student/lib/main_dev.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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';
import 'package:provider/provider.dart';

import 'config/config.dart';

void main() {
void main() async {
await dotenv.load();
runApp(
Provider<Config>(
create: (_) => DevConfig(),
Expand Down
8 changes: 8 additions & 0 deletions frontend/app_student/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions frontend/app_student/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies:
flutter_localizations:
sdk: flutter
intl: any
flutter_dotenv: ^5.1.0

dev_dependencies:
flutter_test:
Expand Down Expand Up @@ -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

Expand Down
Loading