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
121
121
! ** /ios /** /default.perspectivev3
122
122
! /packages /flutter_tools /test /data /dart_dependencies_test /** /.packages
123
123
! /dev /ci /** /Gemfile.lock
124
- /app /env /
125
-
126
124
127
125
/modules /common /.flutter-plugins
128
126
/modules /common /.flutter-plugins-dependencies
Original file line number Diff line number Diff line change @@ -125,9 +125,8 @@ app.*.symbols
125
125
/env * .json
126
126
127
127
# Environment and configuration files (contain sensitive data)
128
- env /.env
129
- env /.settings
130
- env /env_ * .json
128
+ .. /env /.env
129
+ .. /env /env_ * .json
131
130
.env
132
131
.env. *
133
132
* .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 {
46
46
static bool isDevelopment () => instance.flavor == Flavor .dev;
47
47
48
48
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
+ }
49
67
}
Original file line number Diff line number Diff line change 1
1
import 'package:app/main/app.dart' ;
2
2
import 'package:common/init.dart' ;
3
+ import 'package:data/init.dart' ;
3
4
import 'package:domain/init.dart' ;
4
5
import 'package:example_domain/init.dart' ;
5
6
import 'package:example_data/init.dart' ;
@@ -8,6 +9,8 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
8
9
import 'package:get_it/get_it.dart' ;
9
10
import 'package:url_strategy/url_strategy.dart' ;
10
11
12
+ import 'env/env_config.dart' ;
13
+
11
14
void init () async {
12
15
WidgetsFlutterBinding .ensureInitialized ();
13
16
await initialize ();
@@ -18,10 +21,12 @@ void init() async {
18
21
final getIt = GetIt .instance;
19
22
20
23
Future <void > initialize () async {
24
+ await dotenv.load (fileName: FlavorConfig .getEnvFilePath ());
21
25
await CommonInit .initialize (getIt);
22
- await DomainInit .initialize (getIt);
23
26
await DataInit .initialize (getIt);
27
+ await DomainInit .initialize (getIt);
28
+
24
29
// Example Module init
25
- await ExampleDomainInit .initialize (getIt);
26
30
await ExampleDataInit .initialize (getIt);
31
+ await ExampleDomainInit .initialize (getIt);
27
32
}
Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ dependencies:
46
46
path : ../modules/domain
47
47
common :
48
48
path : ../modules/common
49
+ data :
50
+ path : ../modules/data
49
51
50
52
# Remove example dependencies
51
53
example_data :
@@ -81,6 +83,8 @@ flutter:
81
83
# Remove example assets.
82
84
assets :
83
85
- assets/images/
86
+ # remove example suffix
87
+ - env/.env.example
84
88
fonts :
85
89
- family : Roboto Black
86
90
fonts :
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ class EnvConfig {
7
7
8
8
static String env = kDevEnv;
9
9
10
- static String get envConfigFile => 'env/.settings .example' ;
10
+ static String get envConfigFile => 'env/.env .example' ;
11
11
12
12
static String get apiUrl => dotenv.env['API_URL_$env ' ]? .toString () ?? '' ;
13
13
}
Original file line number Diff line number Diff line change 1
1
import 'package:domain/bloc/app/app_cubit.dart' ;
2
2
import 'package:domain/bloc/auth/auth_cubit.dart' ;
3
3
import 'package:domain/services/auth_service.dart' ;
4
- import 'package:flutter_dotenv/flutter_dotenv.dart' ;
5
4
import 'package:get_it/get_it.dart' ;
6
5
7
- import 'env/env_config.dart' ;
8
-
9
6
class DomainInit {
10
7
static Future <void > initialize (GetIt getIt) async {
11
- await dotenv.load (fileName: EnvConfig .envConfigFile);
12
8
//Cubits
13
9
getIt.registerSingleton (AppCubit (getIt ()));
14
10
getIt.registerSingleton (AuthCubit ());
You can’t perform that action at this time.
0 commit comments