Answers for "use env flutter"

0

use env flutter

You can do that by inserting in the .env file:

HOST=localhost
PORT=3000

Add the .env file in the assets section of the pubspec.yaml:

assets:
  - .env

Then, you can change the main function in the main.dart to load the .env file:

Future main() async {
  await DotEnv().load('.env');
  runApp(MyApp());
}

After that, you can get the HOST and PORT anywhere with:

DotEnv().env['PORT'];
DotEnv().env['HOST'];

All these instructions are in the README of the library: https://pub.dev/packages/flutter_dotenv#-readme-tab-
Posted by: Guest on January-09-2021

Browse Popular Code Answers by Language