Skip to content

Commit

Permalink
Enviroment files improvements (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirland authored Nov 25, 2022
1 parent 0c749b6 commit 621b79f
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 24 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions assets/README.md
Original file line number Diff line number Diff line change
@@ -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.
Empty file removed assets/environments/.env
Empty file.
10 changes: 10 additions & 0 deletions environments/README.md
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 1 addition & 1 deletion fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
19 changes: 10 additions & 9 deletions lib/core/common/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -55,7 +55,7 @@ abstract class Config {
Environments.values,
const String.fromEnvironment('ENV'),
) ??
Environments.development;
Environments.dev;

static Future<void> initialize() async {
await _EnvConfig._setupEnv(_environment);
Expand Down Expand Up @@ -149,7 +149,8 @@ abstract class _EnvConfig {

static Future<void> _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'));
}
}
12 changes: 0 additions & 12 deletions lib/gen/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ flutter:
uses-material-design: true
assets:
- assets/
- assets/environments/
- environments/

flutter_gen:
assets:
exclude:
- environments/*
- assets/README.md

flavorizr:
flavors:
Expand Down
2 changes: 1 addition & 1 deletion scripts/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 621b79f

Please sign in to comment.