Notice: You're viewing an old version of the Nylo documentation.
Consider upgrading your project to Nylo 5.20.0.
Getting Started



Nylo provides a .env file which contains global configuration variables like the app name, default locale and your App's environment.

This file is located at the root of your project named ".env".



You can add new variables here and then fetch them using the getEnv() helper.

Accessing values from the .env file

You can access your .env values anywhere in the app using the below helper.

import 'package:nylo_framework/nylo_framework.dart';

String appName = getEnv('APP_NAME');

Environment Configuration

Configuring your applications environment is simple.

First open your .env file and then update the keys in the environment file.

You can also add addtional keys here e.g. SHOW_ADS="false".

Your .env file

APP_NAME="My Super App"

Your Text widget

  "Hello, my app's name is " + getEnv('APP_NAME'),
  overflow: TextOverflow.ellipsis,
  style: TextStyle(fontWeight: FontWeight.bold),

Best practises:

  • Don't store anything sensitive or large.

  • Don't commit your .env file to a (public/private) repository.

Environment Variable Types

The values in your .env file are defined as String's but Nylo will return them if they appear to be Booleans or null values.

.env file Return type
APP_NAME="MySuper App" String
DEBUG_MODE=true Boolean
URL_TERMS=null null

Retrieving Environment Values

Fetching values from your .env file is simple in Nylo, you can call the getEnv(String key) helper.

String appName = getEnv('APP_NAME');

You can also provide a defaultValue if the key doesn't exists in the .env file.
String locale = getEnv('DEFAULT_LOCALE', defaultValue: "en");

int httpConnectionTimeout = getEnv('HTTP_CONNECTION_TIMEOUT', defaultValue: (60 * 1000));

Environment flavours

In Nylo, you can build your application from different environment 'flavours'. This allows you to create separate .env files e.g. 'production', 'staging' or 'developing' and then build your app from the configuration.

Creating an environment flavour

First, make a new file at the root level of your project, e.g. .env.production. Then, you can define all your env variables in this file.

Next, add the new env file to your 'assets' in the pubspec.yaml file.


    - .env
    - .env.production // -- new

Then, from the terminal, build your flutter app by specifying the env file like in the below example.

flutter run --dart-define="ENV_FILE=.env.production"

flutter run --dart-define="ENV_FILE=.env.developing"

// or build

flutter build ios --dart-define="ENV_FILE=.env.developing"

flutter build appbundle --dart-define="ENV_FILE=.env.developing"

The ENV_FILE will default to .env.