dart_dotenv | A simple and easy to use dotenv library for Dart

dart_dotenv

A simple and easy to use dotenv library for Dart (dartlang).

Usage

A simple usage example:

import 'package:dart_dotenv/dart_dotenv.dart';

main(List<String> args) {
  final dotEnv = DotEnv(filePath: '.env');

  // Check if file exists or not.
  print('.env exists ? - ${dotEnv.exists()}');
  // Create a new [filePath] file if not exists.
  print('.env Created New ? - ${dotEnv.createNew()}');
  // Get a specific value from [.env] file.
  print('.env value of "someSpecificKey" ? - ${dotEnv.get("someSpecificKey")}');
  // Get the whole data of [.env] file as [Map<String, String>].
  print('.env data ? - ${dotEnv.getDotEnv()}');
  // Set a new value to and existing key or a completely new set of key and value.
  print('.env append new data ? - ${dotEnv.set("newKey", "newValue")}');
  // Save the new data to `[filePath]` file.
  print('.env save to file ? - ${dotEnv.saveDotEnv()}');
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

Use this package as a library

Depend on it

Run this command:

With Dart:

 $ dart pub add dart_dotenv

With Flutter:

 $ flutter pub add dart_dotenv

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):


dependencies:
  dart_dotenv: ^1.0.1

Alternatively, your editor might support dart pub get or flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:dart_dotenv/dart_dotenv.dart';

example/dart_dotenv_example.dart

import 'package:dart_dotenv/dart_dotenv.dart';
 
void main(List<String> args) {
  final dotEnv = DotEnv(filePath: '.env');

  // Check if file exists or not.
  print('.env exists ? - ${dotEnv.exists()}');
  // Create a new [filePath] file if not exists.
  print('.env Created New ? - ${dotEnv.createNew()}');
  // Get a specific value from [.env] file.
  print('.env value of "someSpecificKey" ? - ${dotEnv.get("someSpecificKey")}');
  // Get the whole data of [.env] file as [Map<String, String>].
  print('.env data ? - ${dotEnv.getDotEnv()}');
  // Set a new value to and existing key or a completely new set of key and value.
  print('.env append new data ? - ${dotEnv.set("newKey", "newValue")}');
  // Save the new data to `[filePath]` file.
  print('.env save to file ? - ${dotEnv.saveDotEnv()}');
}

Download Details:

Author: BLUE-DEVIL1134

Official Website: https://github.com/BLUE-DEVIL1134/dart_dotenv
 

18.25 GEEK