How to Add .env File in Flutter? Last Updated : 16 Nov, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Environment variables are used to store sensitive data such as passwords, API credentials, and other information that should not be written directly in code. It cannot be uploaded to github, gitlab, and many others. It can be done in different ways in different programming languages. But now we will learn to add a .env file in flutter and access its variable. So we can use the package flutter_dotenv. Step By Step ImplementationStep 1: Import Package to pubspec.yaml file Run command in terminal: flutter pub add flutter_dotenvOR Add manually in dependencies: dependencies: flutter_dotenv: ^5.0.2 OR If you using Visual Studio Code you can use these command For Windows - ctrl+shift+P For macOS - command+shift+P after that select add dart dependency and type flutter_dotenv // you can type any other package with these Step 2: Create a .env File in the Project Folder either on lib or asset Step 3: Add these File Paths to the pubspec.yaml fileassets: lib/.env # path to your .envExample: Step 4: Load/Initialize the dotenv file in the Main Function await dotenv.load(fileName: ".env" //path to your .env file); Don't forget to make the main function as future and add async to it. Example: Step 5: Add Variable to .env file// Syntax VAR_NAME = "variable value" // Example COST_FLUTTERWINGS = '$0' // you can use # in .env file for comments # This is a comment Step 6: Get the .env file Variable import 'package:flutter_dotenv/flutter_dotenv.dart'; dotenv.env['VAR_NAME']; // This is to access variable name from .env file Comment More infoAdvertise with us Next Article How to Add .env File in Flutter? F flutterwings Follow Improve Article Tags : Technical Scripter Flutter Technical Scripter 2022 Similar Reads How to Add Firebase to Flutter App? Firebase is a product of Google that helps developers to build, manage, and grow their apps easily. It helps developers to build their apps faster and more securely. No programming is required on the Firebase side which makes it easy to use its features more efficiently. It provides services to Andr 3 min read How to Add Firebase into Flutter in a New Way? Recently Firebase give another option for adding Firebase to Flutter and It is only made for Flutter, As of now we add firebase using the android option for flutter but now we can add using the flutter option that is recently updated by Flutter. Here you can find how to add firebase as an Android in 2 min read How to use Functions of Another File in Flutter? Flutter is an open-source framework by Google for building beautiful, natively compiled, multi-platform applications from a single codebase. A Single codebase means that only we have to write a single code for Android and IOS and others like Desktop  Application, Web Application. So, Today we are go 2 min read How to Add Splash Screen in Flutter App? We all have heard of Flutter right, it's a cross-platform application development tool. Flutter can be used to make Android, IOS, and Web applications with just one code base (Dart programming language). In this article let's see how we can add a splash screen to our applications. What is Splash Scr 3 min read Flutter - Android Studio Not Showing Project Files There are a couple of errors that come up while making an Android app. Making the project requires less time rather than debugging the same project with errors. One such error is that when we develop a project and when we open it after a few days it does not show us the files present in the folder, 3 min read Like