Zujaj / envify_demo

Demonstrates the Implementation of Envify Package in Flutter.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Envify - Your Secret Vault in Flutter

Envify - Your Secret Vault in Flutter

As a Flutter Developer, there comes a time when you need to specify some confidential information in your source code such as API Keys, File Paths, URLs, Client-Side Secret Key etc, so the question arises that how would you:

βœ”οΈ Keep this data confidential.

πŸ’‰ Integrate it without disclosing it inside the source code.

πŸ›‘οΈ Protect it if a hacker dismantles the code.

To get into more details, read the medium article.

Project Structure

envify_demo
β”œβ”€ lib
β”‚  β”œβ”€ config 
β”‚  β”‚  └─ env.dart // The Confidential Information.
β”‚  β”‚  └─ env.g.dart // The Generated File.
β”‚  β”œβ”€ page
β”‚  β”‚  └─ envify_demo.dart // The Demo Page.
β”‚  β”œβ”€ main.dart
β”œβ”€ pubspec.lock
β”œβ”€ pubspec.yaml
β”œβ”€ README.md
β”œβ”€ .env // The Environment File.

Getting Started

  1. Add the envify package in the pubspec.yaml file.

    dependencies:
        flutter:
        sdk: flutter
        # A better way to handle environment variables using `.env` file.
        envify: ^2.0.2
    
    dev_dependencies:
        
        # A build system for Dart code generation and modular compilation.
        build_runner: ^2.1.5
    
        # A code generator for envify.
        envify_generator: ^2.0.2
  2. Add all the files related to envify in the .gitignore file.

    # Some files to ignore.....
    
    # Envify related 
    .env
    env.dart
    env.g.dart
  3. Outside the lib folder, create an Environment file.

    API_KEY = 'PWEP198104102HEWFUQ'
    SITE_KEY = '91310!@31rwd2PZECAA'
    CLIENT_SECRET = 'XXXAd0q39e20q'
    CLIENT_ID = 'John Doe'
  4. Under the config folder, create an env.dart file

    import 'package:envify/envify.dart';
    part 'env.g.dart';
    
    @Envify(name: 'Secret')
    abstract class Secret {
        /// Holds the API_KEY.
        static const api_key = _Secret.api_key;
    
        /// Holds the SITE_KEY.
        static const site_key = _Secret.site_key;
    
        /// Holds the CLIENT_SECRET.
        static const client_secret = _Secret.client_secret;
    
        /// Holds the CLIENT_ID.
        static const client_id = _Secret.client_id;
    }
  5. Generate the env.g.dart using the below command from the terminal.

    flutter pub run build_runner build --delete-conflicting-outputs

FINAL RESULT

Demonstration of App Using Envify on Windows.

TOOLS & LANGUAGE

About

Demonstrates the Implementation of Envify Package in Flutter.


Languages

Language:C++ 48.7%Language:CMake 23.0%Language:Dart 13.2%Language:HTML 11.4%Language:C 2.1%Language:Swift 1.2%Language:Kotlin 0.4%Language:Objective-C 0.1%