dotenv_gen

Creator: coderz1093

Last updated:

0 purchases

dotenv_gen Image
dotenv_gen Images

Languages

Categories

Add to Cart

Description:

dotenv gen

A code generation library to make enviroment variables available at compile time.
Features #
Generates a dart file with values from a .env file allowing you to use those enviroment
variables in your project without commiting them.
Supports and parses not just String but also int, double, bool and enum.
Getting started #
Add the following to your projects pubspec.yaml
dependencies:
dotenv_gen: any

dev_dependencies:
dotenv_gen_runner: any
build_runner: any
copied to clipboard
Usage #
Add a .env file at the root of the project. Syntax and rules for the file can be viewed at dotenv rules.
name=EnvGenTest
copied to clipboard
Create a dart file with your .env keys.
Supported variable types are:

String
int
double
bool
enum

import 'package:dotenv_gen/dotenv_gen.dart';

part 'example.g.dart';

@DotEnvGen()
abstract class Env {
// factory to init the generated class
const factory Env() = _$Env;

// an empty constructor is required
const Env._();

// value is required
String get name;

// use default value if no value provided
final int version = 1;

// null if no value provided
String? get description;

// any functions etc will be inherited
void func() {}
}
copied to clipboard
Then run the generator:
# dart
pub run build_runner build
# flutter
flutter pub run build_runner build
copied to clipboard
Issues #
Changing values in the .env file and re-running build_runner may not update file due to a caching

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.