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

Configuration



Introduction

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".

APP_NAME=Nylo
APP_ENV=local
APP_DEBUG=true
APP_URL=https://nylo.dev

ASSET_PATH_PUBLIC=public/assets/
ASSET_PATH_IMAGES=public/assets/images
TIMEZONE=UTC
DEFAULT_LOCALE=en

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

Text(
  "Hello, my app's name is " + getEnv('APP_NAME'),
  textAlign: TextAlign.center,
  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));