-
Notifications
You must be signed in to change notification settings - Fork 0
Dotenv setup with environment selector & interceptors #108
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
Merged
+265
−56
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ce0b660
wip dotenv setup
aguskoll af38044
dotenv setup
aguskoll 35fa7b0
environment selector
aguskoll 965de65
auth token interceptor
aguskoll f935103
removed files that should be in gitignore
aguskoll a3fdb9c
show env selector only debug mode
aguskoll 7d152cd
primary v0 instead of black
aguskoll 4b75dc0
fixed spacing
aguskoll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # The .env file MUST be in .gitignore | ||
| # Delete this file after creating .env | ||
| # | ||
| # Each flavor (dev/qa/prod) uses the same .env file but reads | ||
| # different variables based on the suffix: | ||
| # - Development (main_dev.dart) → reads *_DEV variables | ||
| # - QA/Staging (main_qa.dart) → reads *_QA variables | ||
| # - Production (main.dart) → reads *_PROD variables | ||
|
|
||
| API_URL_DEV=https://your-api-url-dev.com | ||
| API_URL_QA=https://your-api-url-qa.com | ||
| API_URL_PROD=https://your-api-url-prod.com | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import 'package:domain/env/env_config.dart'; | ||
| import 'package:domain/services/environment_service.dart'; | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| import '../../../main/init.dart'; | ||
|
|
||
| class EnvironmentSelector extends StatelessWidget { | ||
| EnvironmentSelector({ | ||
| super.key, | ||
| }); | ||
|
|
||
| final EnvironmentService environmentService = getIt<EnvironmentService>(); | ||
|
|
||
| DropdownMenuItem<String> _item( | ||
| String value, String label, TextStyle textStyle) => | ||
| DropdownMenuItem<String>( | ||
| value: value, | ||
| child: Padding( | ||
| padding: const EdgeInsets.symmetric(horizontal: 8.0), | ||
| child: Text(label, style: textStyle), | ||
| ), | ||
| ); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| final textStyle = | ||
| Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.black); | ||
agustinkoll-rootstrap marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| final items = <DropdownMenuItem<String>>[ | ||
| _item(EnvConfig.kDevEnv, 'Development', textStyle!), | ||
| _item(EnvConfig.kQaEnv, 'QA', textStyle), | ||
| _item(EnvConfig.kProdEnv, 'Production', textStyle), | ||
| ]; | ||
|
|
||
| return DropdownButtonFormField<String>( | ||
| initialValue: EnvConfig.env, | ||
| style: textStyle, | ||
| decoration: InputDecoration( | ||
| labelText: 'Environment', | ||
| border: const OutlineInputBorder(), | ||
| prefixIcon: const Icon(Icons.settings), | ||
| labelStyle: textStyle, | ||
| ), | ||
| items: items, | ||
| onChanged: (value) => environmentService.setEnvironment(value!), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
modules/data/lib/network/config/environment_service_impl.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import 'package:data/network/config/network_config.dart'; | ||
| import 'package:dio/dio.dart'; | ||
| import 'package:domain/env/env_config.dart'; | ||
| import 'package:domain/services/environment_service.dart'; | ||
|
|
||
| class EnvironmentServiceImpl extends EnvironmentService { | ||
| final Dio _dio; | ||
|
|
||
| EnvironmentServiceImpl(this._dio); | ||
|
|
||
| @override | ||
| void setEnvironment(String env) { | ||
| EnvConfig.env = env; | ||
| NetworkConfig.updateBaseUrl(_dio); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,44 @@ | ||
| import 'package:dio/dio.dart'; | ||
| import 'package:domain/env/env_config.dart'; | ||
| import 'package:flutter/foundation.dart'; | ||
|
|
||
| import '../interceptors/auth_token_interceptor.dart'; | ||
| import 'network_constants.dart'; | ||
|
|
||
| class NetworkConfig { | ||
| static Dio provideDio() { | ||
| static Dio provideDio(AuthTokenInterceptor? authTokenInterceptor) { | ||
| final options = BaseOptions( | ||
| baseUrl: NetworkConstants.baseUrl, | ||
| baseUrl: EnvConfig.apiUrl, | ||
| connectTimeout: const Duration( | ||
| seconds: NetworkConstants.connectTimeout, | ||
| ), | ||
| receiveTimeout: const Duration( | ||
| seconds: NetworkConstants.receiveTimeout, | ||
| ), | ||
| ); | ||
| return Dio(options); | ||
|
|
||
| final dio = Dio(options); | ||
|
|
||
| // Add debug logging only in debug mode | ||
| if (kDebugMode) { | ||
| dio.interceptors.add(LogInterceptor( | ||
| requestBody: true, | ||
| responseBody: true, | ||
| requestHeader: true, | ||
| responseHeader: true, | ||
| error: true, | ||
| logPrint: (object) => debugPrint(object.toString()), | ||
| )); | ||
| } | ||
|
|
||
| if (authTokenInterceptor != null) { | ||
| dio.interceptors.add(authTokenInterceptor); | ||
| } | ||
|
|
||
| return dio; | ||
| } | ||
|
|
||
| static void updateBaseUrl(Dio dio) { | ||
| dio.options.baseUrl = EnvConfig.apiUrl; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.