Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: CI

on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]

# flutter_secure_dotenv ^2.0.0 is not yet on pub.dev. We check out its
# matching branch and generate a pubspec_overrides.yaml that redirects
# the hosted dependency to the local checkout.
#
# Once flutter_secure_dotenv is published, simplify back to a single
# checkout and remove the override steps.
#
# Push order: flutter_secure_dotenv first, then this repo.

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: flutter_secure_dotenv_generator
- uses: actions/checkout@v4
with:
repository: mfazrinizar/flutter_secure_dotenv
ref: ${{ github.base_ref || github.ref_name }}
path: flutter_secure_dotenv
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- name: Override flutter_secure_dotenv to local path
shell: bash
run: |
cat > pubspec_overrides.yaml << 'EOF'
dependency_overrides:
flutter_secure_dotenv:
path: ../flutter_secure_dotenv
EOF
working-directory: flutter_secure_dotenv_generator
- run: dart pub get
working-directory: flutter_secure_dotenv_generator
- run: dart format --set-exit-if-changed .
working-directory: flutter_secure_dotenv_generator
- run: dart analyze --fatal-infos
working-directory: flutter_secure_dotenv_generator

test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
sdk: [stable, "3.8.0"]
steps:
- uses: actions/checkout@v4
with:
path: flutter_secure_dotenv_generator
- uses: actions/checkout@v4
with:
repository: mfazrinizar/flutter_secure_dotenv
ref: ${{ github.base_ref || github.ref_name }}
path: flutter_secure_dotenv
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ matrix.sdk }}
- name: Override flutter_secure_dotenv to local path
shell: bash
run: |
cat > pubspec_overrides.yaml << 'EOF'
dependency_overrides:
flutter_secure_dotenv:
path: ../flutter_secure_dotenv
EOF
working-directory: flutter_secure_dotenv_generator
- run: dart pub get
working-directory: flutter_secure_dotenv_generator
- run: dart test
working-directory: flutter_secure_dotenv_generator

dry-run:
name: Publish Dry Run
runs-on: ubuntu-latest
needs: [analyze, test]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
with:
path: flutter_secure_dotenv_generator
- uses: actions/checkout@v4
with:
repository: mfazrinizar/flutter_secure_dotenv
ref: main
path: flutter_secure_dotenv
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- name: Override flutter_secure_dotenv to local path
shell: bash
run: |
cat > pubspec_overrides.yaml << 'EOF'
dependency_overrides:
flutter_secure_dotenv:
path: ../flutter_secure_dotenv
EOF
working-directory: flutter_secure_dotenv_generator
- run: dart pub get
working-directory: flutter_secure_dotenv_generator
- run: dart pub publish --dry-run
working-directory: flutter_secure_dotenv_generator

pana:
name: Package Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: flutter_secure_dotenv_generator
- uses: actions/checkout@v4
with:
repository: mfazrinizar/flutter_secure_dotenv
ref: ${{ github.base_ref || github.ref_name }}
path: flutter_secure_dotenv
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- run: dart pub global activate pana
- name: Override flutter_secure_dotenv to local path
shell: bash
run: |
cat > pubspec_overrides.yaml << 'EOF'
dependency_overrides:
flutter_secure_dotenv:
path: ../flutter_secure_dotenv
EOF
working-directory: flutter_secure_dotenv_generator
- run: dart pub get
working-directory: flutter_secure_dotenv_generator
- run: dart pub global run pana --no-warning .
working-directory: flutter_secure_dotenv_generator
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ pubspec.lock

.vscode/

.env*
.env*
!example/.env

# Local development overrides
pubspec_overrides.yaml
7 changes: 7 additions & 0 deletions .pubignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Files to exclude from pub.dev publishing.
# See https://dart.dev/go/pubignore

.dart_tool/
pubspec.lock
.vscode/
pubspec_overrides.yaml
47 changes: 35 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
## 1.0.0

- Initial version.
- Update dependencies, refactor codes and continue the discontinued secure_dotenv_generator
## 2.0.0

- **BREAKING**: Updated `source_gen` from `^2.0.0` to `^4.2.0` (addresses [#3](https://github.com/mfazrinizar/flutter_secure_dotenv_generator/issues/3)).
- Migrated from `TypeChecker.fromRuntime` to `TypeChecker.fromUrl` (source_gen 4.x breaking change).
- Added `inPackage` to `GeneratorForAnnotation` for precise annotation matching.
- **BREAKING**: Updated `build` from `^2.4.2` to `>=3.0.0 <5.0.0`.
- **BREAKING**: Updated `analyzer` from `^7.2.0` to `>=8.0.0 <11.0.0`.
- Migrated from `element.enclosingElement3` to `element.enclosingElement`.
- Migrated from `interface.augmented.lookUpGetter/lookUpSetter` to `interface.lookUpGetter/lookUpSetter`.
- Migrated from `accessor.variable2` to `accessor.variable`.
- Migrated from `interface.accessors` to `interface.getters`/`interface.setters`.
- Migrated from `library.importedLibraries` to `library.firstFragment.libraryImports`.
- **BREAKING**: Updated `pointycastle` from `^3.9.1` to `^4.0.0`.
- **BREAKING**: Minimum Dart SDK bumped from `^3.6.0` to `^3.8.0`.
- **Fix**: Generator no longer processes static/private fields (e.g. `_encryptionKey`, `_iv`) as environment variables.
- Updated `flutter_secure_dotenv` dependency to `^2.0.0`.
- Updated `source_helper` to `^1.3.10`, `lints` to `^6.1.0`, `test` to `^1.29.0`, `build_runner` to `^2.11.1`.
- Updated example to use secure key loading (removed `String.fromEnvironment` pattern).
- Added 100% `public_member_api_docs` coverage with library-level dartdoc.
- Enhanced test coverage from 3 to 14 tests.
- Added GitHub Actions CI workflow with dual-checkout and auto-generated `pubspec_overrides.yaml`.
- Added `CONTRIBUTING.md`.

## 1.0.1
## 1.0.5

- Minor typo fixes
- Fix enum typePrefix empty building issue

## 1.0.2
## 1.0.4

- Fix building issue
- Fix building without encryption

## 1.0.3

- Fix FormatterException caused by dart.core type prefix

## 1.0.4
## 1.0.2

- Fix building without encryption
- Fix building issue

## 1.0.5
## 1.0.1

- Fix enum typePrefix empty building issue
- Minor typo fixes

## 1.0.0

- Initial version.
- Update dependencies, refactor codes and continue the discontinued secure_dotenv_generator
74 changes: 74 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributing to flutter_secure_dotenv_generator

Thank you for your interest in contributing! This guide will help you get started.

## Getting Started

1. Fork the repository
2. Clone your fork:
```bash
git clone https://github.com/<your-username>/flutter_secure_dotenv_generator.git
```
3. Install dependencies:
```bash
dart pub get
```

### Local Development with flutter_secure_dotenv

During development you may want to test against a local copy of `flutter_secure_dotenv`. Create a `pubspec_overrides.yaml` (git-ignored) in the project root:

```yaml
dependency_overrides:
flutter_secure_dotenv:
path: ../flutter_secure_dotenv
```

## Development Workflow

### Branching

- `main` — stable releases published to pub.dev
- `dev` — active development; PRs should target this branch

Create a feature branch from `dev`:

```bash
git checkout -b feature/my-feature dev
```

### Code Quality

Before submitting a PR, make sure all checks pass:

```bash
dart format --set-exit-if-changed .
dart analyze --fatal-infos
dart test
```

CI runs these automatically on every push and pull request.

### Tests

All new features and bug fixes **must** include tests. Run the test suite with:

```bash
dart test
```

## Pull Requests

1. Keep PRs focused — one feature or fix per PR.
2. Write clear commit messages.
3. Update `CHANGELOG.md` under an `## Unreleased` section.
4. Ensure CI passes before requesting review.

## Reporting Issues

- Use [GitHub Issues](https://github.com/mfazrinizar/flutter_secure_dotenv_generator/issues).
- Include Dart SDK version, package version, and a minimal reproduction.

## Code of Conduct

Be respectful and constructive in all interactions. We follow the [Dart community guidelines](https://dart.dev/community).
9 changes: 6 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ linter:
rules:
- public_member_api_docs

# analyzer:
# exclude:
# - path/to/excluded/files/**
analyzer:
exclude:
# The example references env.g.dart which is produced by build_runner.
# Without running the generator the file doesn't exist, causing
# uri_has_not_been_generated errors during static analysis.
- example/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints
Expand Down
28 changes: 15 additions & 13 deletions example/flutter_secure_dotenv_generator_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@ import 'package:flutter_secure_dotenv/flutter_secure_dotenv.dart';

part 'env.g.dart';

@DotEnvGen(
filename: '.env',
fieldRename: FieldRename.screamingSnake,
)
/// Example using the "Hardcoded Key + Gitignore" pattern.
///
/// This file (env.dart) is GITIGNORED. A template `env.example.dart` with
/// placeholder values is committed instead. See SECURITY.md in
/// flutter_secure_dotenv for details.

@DotEnvGen(filename: '.env', fieldRename: FieldRename.screamingSnake)
abstract class Env {
static Env create() {
String encryptionKey = const String.fromEnvironment(
"APP_ENCRYPTION_KEY"); // On build, change with your generated encryption key (use dart-define for String.fromEnvironment)
String iv = const String.fromEnvironment(
"APP_IV_KEY"); // On build, change with your generated iv (use dart-define for String.fromEnvironment)
return Env(encryptionKey, iv);
}
// These values come from the temporary encryption_key.json generated by
// build_runner. Copy them here, then delete the JSON file.
static const _encryptionKey = 'YOUR_BASE64_ENCRYPTION_KEY';
static const _iv = 'YOUR_BASE64_IV';

static Env create() => Env(_encryptionKey, _iv);

const factory Env(String encryptionKey, String iv) = _$Env;

const Env._();

@FieldKey(defaultValue: "")
@FieldKey(defaultValue: '')
String get apiBaseUrl;

@FieldKey(defaultValue: "")
@FieldKey(defaultValue: '')
String get apiWebSocketUrl;
}
13 changes: 9 additions & 4 deletions lib/flutter_secure_dotenv_generator.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/// Code generator for [flutter_secure_dotenv](https://pub.dev/packages/flutter_secure_dotenv).
///
/// Reads `.env` files at build time, encrypts the values with AES-CBC, and
/// emits a `part` file containing the encrypted data.
library;

import 'package:build/build.dart';
import 'package:source_gen/source_gen.dart';

Expand All @@ -7,7 +13,6 @@ import 'src/annotation_generator.dart';
///
/// Takes [options] as a parameter to configure the builder.
Builder flutterSecureDotEnvAnnotation(BuilderOptions options) =>
SharedPartBuilder(
[FlutterSecureDotEnvAnnotationGenerator(options)],
'flutter_secure_dot_env_annotation',
);
SharedPartBuilder([
FlutterSecureDotEnvAnnotationGenerator(options),
], 'flutter_secure_dot_env_annotation');
Loading