File tree Expand file tree Collapse file tree 9 files changed +47
-22
lines changed Expand file tree Collapse file tree 9 files changed +47
-22
lines changed Original file line number Diff line number Diff line change @@ -121,8 +121,6 @@ app.*.symbols
121121! ** /ios /** /default.perspectivev3
122122! /packages /flutter_tools /test /data /dart_dependencies_test /** /.packages
123123! /dev /ci /** /Gemfile.lock
124- /app /env /
125-
126124
127125/modules /common /.flutter-plugins
128126/modules /common /.flutter-plugins-dependencies
Original file line number Diff line number Diff line change @@ -125,9 +125,8 @@ app.*.symbols
125125/env * .json
126126
127127# Environment and configuration files (contain sensitive data)
128- env /.env
129- env /.settings
130- env /env_ * .json
128+ .. /env /.env
129+ .. /env /env_ * .json
131130.env
132131.env. *
133132* .env
Original file line number Diff line number Diff line change 1+ # The .env file MUST be in .gitignore
2+ #
3+ # Each flavor (dev/qa/prod) uses the same .env file but reads
4+ # different variables based on the suffix:
5+ # - Development (main_dev.dart) → reads *_DEV variables
6+ # - QA/Staging (main_qa.dart) → reads *_QA variables
7+ # - Production (main.dart) → reads *_PROD variables
8+ #
9+ # Access variables in domain/lib/env/env_config.dart:
10+ # static String get apiUrl => dotenv.env['API_URL_$env']?.toString() ?? '';
11+
12+ API_URL_DEV = https://your-api-url-dev.com
13+ API_URL_QA = https://your-api-url-qa.com
14+ API_URL_PROD = https://your-api-url-prod.com
15+
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -46,4 +46,22 @@ class FlavorConfig {
4646 static bool isDevelopment () => instance.flavor == Flavor .dev;
4747
4848 static bool isQA () => instance.flavor == Flavor .qa;
49+
50+ /// Returns the environment file path (single .env file for all flavors)
51+ ///
52+ /// SETUP INSTRUCTIONS:
53+ /// 1. Navigate to app/env/ directory
54+ /// 2. Create a .env file (must be in .gitignore):
55+ /// cp .env.example .env
56+ /// 3. Add your environment variables with flavor suffixes:
57+ /// API_URL_DEV=https://dev-api.example.com
58+ /// API_URL_QA=https://qa-api.example.com
59+ /// API_URL_PROD=https://api.example.com
60+ /// 4. The active flavor determines which suffix is used (_DEV, _QA, _PROD)
61+ /// 5. Access variables in domain/lib/env/env_config.dart using:
62+ /// static String get apiUrl => dotenv.env['API_URL_$env']?.toString() ?? '';
63+ /// (The $env automatically appends DEV, QA, or PROD based on active flavor)
64+ static String getEnvFilePath () {
65+ return 'env/.env.example' ;
66+ }
4967}
Original file line number Diff line number Diff line change 11import 'package:app/main/app.dart' ;
22import 'package:common/init.dart' ;
3+ import 'package:data/init.dart' ;
34import 'package:domain/init.dart' ;
45import 'package:example_domain/init.dart' ;
56import 'package:example_data/init.dart' ;
@@ -8,6 +9,8 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
89import 'package:get_it/get_it.dart' ;
910import 'package:url_strategy/url_strategy.dart' ;
1011
12+ import 'env/env_config.dart' ;
13+
1114void init () async {
1215 WidgetsFlutterBinding .ensureInitialized ();
1316 await initialize ();
@@ -18,10 +21,12 @@ void init() async {
1821final getIt = GetIt .instance;
1922
2023Future <void > initialize () async {
24+ await dotenv.load (fileName: FlavorConfig .getEnvFilePath ());
2125 await CommonInit .initialize (getIt);
22- await DomainInit .initialize (getIt);
2326 await DataInit .initialize (getIt);
27+ await DomainInit .initialize (getIt);
28+
2429 // Example Module init
25- await ExampleDomainInit .initialize (getIt);
2630 await ExampleDataInit .initialize (getIt);
31+ await ExampleDomainInit .initialize (getIt);
2732}
Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ dependencies:
4646 path : ../modules/domain
4747 common :
4848 path : ../modules/common
49+ data :
50+ path : ../modules/data
4951
5052 # Remove example dependencies
5153 example_data :
@@ -81,6 +83,8 @@ flutter:
8183 # Remove example assets.
8284 assets :
8385 - assets/images/
86+ # remove example suffix
87+ - env/.env.example
8488 fonts :
8589 - family : Roboto Black
8690 fonts :
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ class EnvConfig {
77
88 static String env = kDevEnv;
99
10- static String get envConfigFile => 'env/.settings .example' ;
10+ static String get envConfigFile => 'env/.env .example' ;
1111
1212 static String get apiUrl => dotenv.env['API_URL_$env ' ]? .toString () ?? '' ;
1313}
Original file line number Diff line number Diff line change 11import 'package:domain/bloc/app/app_cubit.dart' ;
22import 'package:domain/bloc/auth/auth_cubit.dart' ;
33import 'package:domain/services/auth_service.dart' ;
4- import 'package:flutter_dotenv/flutter_dotenv.dart' ;
54import 'package:get_it/get_it.dart' ;
65
7- import 'env/env_config.dart' ;
8-
96class DomainInit {
107 static Future <void > initialize (GetIt getIt) async {
11- await dotenv.load (fileName: EnvConfig .envConfigFile);
128 //Cubits
139 getIt.registerSingleton (AppCubit (getIt ()));
1410 getIt.registerSingleton (AuthCubit ());
You can’t perform that action at this time.
0 commit comments