📜  使用 env flutter - 任何代码示例

📅  最后修改于: 2022-03-11 14:57:34.890000             🧑  作者: Mango

代码示例1
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-