Flutter. Using environment variables.

How to implement functionality for using
.env
variables? Let’s see…
To use environment variables from .env
files we will use flutter_dotenv package.
Step 1
First we’ll need to add flutter_dotenv package to our dependencies:
flutter_dotenv: ^2.1.0
Step 2
Import flutter_dotenv package in main.dart
file:
import 'package:flutter_dotenv/flutter_dotenv.dart';
Step 3
Next, we will change our main method
from
void main() => runApp(MyApp());
to
Future main() async {
await DotEnv().load('.env');
runApp(MyApp());
}
Step 4
To extract .env
variable, VAR_NAME=HELLO_WORLD
, for example, we will need to use this syntax:
import 'package:flutter_dotenv/flutter_dotenv.dart';// some classprint(DotEnv().env['VAR_NAME'])
