Brother Cat said

Sometimes we need to hide sensitive information in the project, such as your Ali OSS account AccessKey, writing code to upload the git warehouse, it is a very dangerous thing, so we need to use the environment variable scheme to hide, remember your The .env file should be added to the .gitignore file for filtering.

Old iron remember to forward, Brother Mao will present more Flutter good articles~~~~

WeChat group ducafecat

b Station https://space.bilibili.com/404904528

original

https://medium.com/flutter-community/learn-the-best-way-to-hide-sensitive-keys-in-your-flutter-app-ac7638435401

Code

https://github.com/Wizpna/flutter_dotenv_tutorial.git

reference

text

I am very happy to write about this topic, because this is an area of knowledge that mobile app developers must have little or known.

As an app developer, developing and deploying apps on the Google Play Store or Apple Store does not mean that you have exhausted the mobile app development cycle.

The mobile application development cycle also includes improving application security.

That's why I shared this article so that you will learn how to hide sensitive security keys in your Flutter application.

At the end of this article, you will learn how to use a Flutter_dotenv to hide sensitive keys in your Flutter application.

https://pub.dev/packages/flutter_dotenv

So let's get started

Use Visual Studio, IntelliJ or Android Studio to create your flutter application, then open the "pubspec.yaml" file and install the following packages.

dependencies:
  flutter_dotenv: ^5.0.0

Create a .env file in the root directory of your flutter project

Add the newly created .env file to the asset package in the pubspec.yaml file.

assets:
  - .env

Please note: add newly created ones. In the pubspec.yaml file, please run flutter Pub get in the terminal, or click Pub get in IntelliJ or Android Studio to add the file to the current working directory folder.

It was successfully added. Add your sensitive keys in the pubspec.yaml file. The env file you created. (For example, see the picture below)

The next step is to initialize/load the contents of the .env file in the main.dart file, as shown below:

The next step will be to visit. Ring file. You can visit. Use the code below.

dotenv.env['VAR_NAME'];

Please refer to the picture below for a correct understanding

Use a physical device or simulator to test and run the project

Please note: For the sake of this tutorial, I have to show the keys I added in my sensitivity. Because I want you all to see it, understand how to store sensitive keys in an env file, and access it from anywhere in the flutter application.

This mode of storing sensitive keys in the env file helps to securely guide the sensitive keys from being exposed when hackers decompile the application.

Always remember to add. The file is included as an entry in your .gitignore file. (1) The .gitignore file is a plain text file, in which each line contains files/directories not included in the git working copy. )

If you read this, congratulations!

This is the source code of the project you just participated in.

https://github.com/Wizpna/flutter_dotenv_tutorial.git

If you find this article helpful and educational, please hit the high-five button as many times as possible to show your support


© Cat brother

https://ducafecat.tech/

https://github.com/ducafecat

Past

Open source

GetX Quick Start

https://github.com/ducafecat/getx_quick_start

News client

https://github.com/ducafecat/flutter_learn_news

strapi manual translation

https://getstrapi.cn

WeChat discussion group ducafecat

Series collection

Translation

https://ducafecat.tech/categories/%E8%AF%91%E6%96%87/

Open source project

https://ducafecat.tech/categories/%E5%BC%80%E6%BA%90/

Dart programming language basics

https://space.bilibili.com/404904528/channel/detail?cid=111585

Getting started with Flutter zero foundation

https://space.bilibili.com/404904528/channel/detail?cid=123470

Flutter actual combat from scratch news client

https://space.bilibili.com/404904528/channel/detail?cid=106755

Flutter component development

https://space.bilibili.com/404904528/channel/detail?cid=144262

Flutter Bloc

https://space.bilibili.com/404904528/channel/detail?cid=177519

Flutter Getx4

https://space.bilibili.com/404904528/channel/detail?cid=177514

Docker Yapi

https://space.bilibili.com/404904528/channel/detail?cid=130578


独立开发者_猫哥
666 声望126 粉丝