diff --git a/README.md b/README.md index b582787..9056980 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,12 @@ These components are injected in the Cubits using [get_it][get_it]. ## Project Setup +## Environment setup +The environment variables are defined in the `default.env` file located in `/environments/` folder. +You can define different environments for different environments, for example, you can have a `dev.env` for development and a `prod.env` for production. +If you need to add a privete environment variable, you can create a `${env}.private.env` file in the environments folder and it will be ignored by git. + +## Firebase Setup To run this project, you need to config the Firebase project. You can do it by executing the following command: diff --git a/analysis_options.yaml b/analysis_options.yaml index f9b5e3a..922aaf7 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -135,6 +135,7 @@ analyzer: - '**/*.gen.dart' - '**/*.gr.dart' - 'lib/generated_plugin_registrant.dart' + - 'lib/gen/assets.gen.dart' - 'lib/firebase_options_*.dart' errors: invalid_annotation_target: ignore diff --git a/assets/README.md b/assets/README.md new file mode 100644 index 0000000..decfa2a --- /dev/null +++ b/assets/README.md @@ -0,0 +1 @@ +Flutter application assets are taken from the assets folder. This folder contains the assets used by the application, such as images, fonts, and other files. diff --git a/assets/environments/.env b/assets/environments/.env deleted file mode 100644 index e69de29..0000000 diff --git a/environments/README.md b/environments/README.md new file mode 100644 index 0000000..d205184 --- /dev/null +++ b/environments/README.md @@ -0,0 +1,10 @@ +Application environments are taken from the environments folder. +This folder contains the environment variables used by the application, such as API keys, and other files. + +The available environment files are: +- default.env: The default environment variables used by the application. +- dev.env: The development environment variables used by the application. +- private.dev.env: The private development environment variables used by the application. +- prod.env: The production environment variables used by the application. +- private.prod.env: The private production environment variables used by the application. + diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 911368a..74f7ca1 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -69,7 +69,7 @@ lane :lint_code_metrics do end flutter_command(command: "pub run dart_code_metrics:metrics check-unused-code lib --fatal-unused") - flutter_command(command: "pub run dart_code_metrics:metrics check-unused-files lib --fatal-unused") + flutter_command(command: "pub run dart_code_metrics:metrics check-unused-files lib --fatal-unused --exclude=lib/gen/assets.gen.dart") end diff --git a/lib/core/common/config.dart b/lib/core/common/config.dart index ba80136..040b4b4 100644 --- a/lib/core/common/config.dart +++ b/lib/core/common/config.dart @@ -7,27 +7,27 @@ import 'package:flutter/foundation.dart'; import 'package:fluttips/core/common/extension/string_extensions.dart'; import 'package:fluttips/core/common/helper/enum_helpers.dart'; import 'package:fluttips/core/common/helper/env_helper.dart'; -import 'package:fluttips/gen/assets.gen.dart'; enum Environments { - development, - production, + dev, + prod, } extension EnviromentPath on Environments { String get fileName { switch (this) { - case Environments.development: + case Environments.dev: return 'dev'; - case Environments.production: + case Environments.prod: return 'prod'; } } - String get path => 'assets/environments/$fileName'; + String get path => '${Config._environmentFolder}/$fileName'; } abstract class Config { + static const String _environmentFolder = 'environments'; static final num maxDatabaseIntValue = pow(2, 32) - 1; static const int durationAnimation = 150; @@ -55,7 +55,7 @@ abstract class Config { Environments.values, const String.fromEnvironment('ENV'), ) ?? - Environments.development; + Environments.dev; static Future initialize() async { await _EnvConfig._setupEnv(_environment); @@ -149,7 +149,8 @@ abstract class _EnvConfig { static Future _setupEnv(Environments env) async { _envFileEnv - ..addAll(await loadEnvs(Assets.environments.env)) - ..addAll(await loadEnvs('${env.path}.env')); + ..addAll(await loadEnvs('${Config._environmentFolder}/default.env')) + ..addAll(await loadEnvs('${env.path}.env')) + ..addAll(await loadEnvs('${env.path}.private.env')); } } diff --git a/lib/gen/assets.gen.dart b/lib/gen/assets.gen.dart index 849ff6e..ad38508 100644 --- a/lib/gen/assets.gen.dart +++ b/lib/gen/assets.gen.dart @@ -9,20 +9,8 @@ import 'package:flutter/widgets.dart'; -class $AssetsEnvironmentsGen { - const $AssetsEnvironmentsGen(); - - /// File path: assets/environments/.env - String get env => 'assets/environments/.env'; - - /// List of all assets - List get values => [env]; -} - class Assets { Assets._(); - - static const $AssetsEnvironmentsGen environments = $AssetsEnvironmentsGen(); } class AssetGenImage { diff --git a/pubspec.yaml b/pubspec.yaml index d1cc5c6..1931548 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -70,7 +70,13 @@ flutter: uses-material-design: true assets: - assets/ - - assets/environments/ + - environments/ + +flutter_gen: + assets: + exclude: + - environments/* + - assets/README.md flavorizr: flavors: diff --git a/scripts/checks.sh b/scripts/checks.sh index 29af7e1..414b23e 100755 --- a/scripts/checks.sh +++ b/scripts/checks.sh @@ -20,4 +20,4 @@ echo "$result" fvm flutter pub run dart_code_metrics:metrics check-unused-code lib --fatal-unused || error "Linter error" -fvm flutter pub run dart_code_metrics:metrics check-unused-files lib --fatal-unused || error "Linter error" +fvm flutter pub run dart_code_metrics:metrics check-unused-files lib --fatal-unused --exclude=lib/gen/assets.gen.dart || error "Linter error"