https://pub.dev/packages/envied
https://codewithandrea.com/articles/flutter-api-keys-dart-define-env-files/
$ flutter pub add envied
$ flutter pub add --dev envied_generator
$ flutter pub add --dev build_runner
lib 폴더 내에
.env
env.dart 파일 생성
KEY1=VALUE1
KEY2=VALUE2
USER_API_KEY=qwerasdfq1-ewqfij-3jijkjij
// lib/env/env.dart
import 'package:envied/envied.dart';
part 'env.g.dart';
@Envied(path: '.env.dev')
abstract class Env {
@EnviedField(varName: 'KEY1')
static const key1 = _Env.key1;
@EnviedField()
static const KEY2 = _Env.KEY2;
@EnviedField(defaultValue: 'test_')
static const key3 = _Env.key3;
}
dart run build_runner build
.env 파일에 수정이 있을때 아래의 명령어 사용
dart run build_runner clean
dart run build_runner build --delete-conflicting-outputs