npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flutter-env

v1.0.3

Published

Switch between different Flutter environments.

Downloads

11

Readme

flutter-env

Switch between different Flutter environments.

Useful if you have multiple environments that all have different app id's, API endpoints and Firebase projects.

Installation

Install this packages globally:

npm i -g flutter-env

Preparation

  1. Create the flutter-env.json and .flutter-env file in the root of your Flutter project.
  2. Run flutter-env flutter-env-example to see an example of the flutter-env.json file and use this as the base for your file.
  3. Commit these files.
  4. Run flutter-env switch-to prod to switch to the prod environment (or some other environment you have defined in the flutter-env.json file).

The flutter-env.json file

This file defines all properties for each environment. The default environment must be present defines the default properties and their values. These values can be overruled in the other environments you define. For example below we have defined 3 environments: dev, test and prod. The dev environment overrules the app_id and some env variables. The test and prod environments only overrule the app_id.

Fields

app_id

The app ID.

env_file and env_class

All variables that are defined in the env section will be written to the file env_file as static const variables of the env_class class.

env

See above - these are the variables of the env_class class in the env_file file.

Example

{
    "default": {
        "env_file": "my_env.dart",
        "env_class": "MyEnv",
        "env": {
            "apiProtocol": {
                "value": "https",
                "type": "String"
            },
            "apiHost": {
                "value": "www.example.com",
                "type": "String"
            },
            "sentryDns": {
                "value": "https://sentry.com",
                "type": "String"
            }
        }
    },
    "dev": {
        "app_id": "my.dev.app",
        "env": {
            "apiProtocol": {
                "value": "http"
            },
            "apiHost": {
                "value": "localhost:8080"
            }
        }
    },
    "test": {
        "app_id": "my.test.app"
    },
    "prod": {
        "app_id": "my.prod.app"
    }
}

Firebase

If you want to use multiple Firebase projects for your environments, first follow the steps below. After that you can add the with-fb option to the switch-to command.

Add the first Firebase project

Execute the flutterfire configure command. This will add the following files to your Flutter project:

  • android/app/google-services.json
  • ios/firebase_app_id_file.json
  • ios/Runner/GoogleService-Info.plist
  • lib/firebase_options.dart

Append the Firebase files with the environment name

Now move these 4 files and add _[environment] to it. For example if this is the dev environment, the files will become:

  • android/app/google-services_dev.json
  • ios/firebase_app_id_file_dev.json
  • ios/Runner/GoogleService-Info_dev.plist
  • lib/firebase_options_dev.dart

Add the second Firebase project

Execute the following flutterfire command: flutterfire configure -p [project-name] -i [app-id] -a [app-id]. The -i and -a are the app ids of the iOS and Android app. This will add again the 4 files to your Flutter project.

Append the Firebase files with the environment name

Now move these 4 files and add _[environment] to it. For example if this is the prod environment, the files will become:

  • android/app/google-services_prod.json
  • ios/firebase_app_id_file_prod.json
  • ios/Runner/GoogleService-Info_prod.plist
  • lib/firebase_options_prod.dart

Commit your changes

Now commit your files, so we have all files.

Commands

flutter-env check

A basic check if you have the required files.

flutter-env switch-to

Switch to a specific environment.

For example to switch to the dev environment:

flutter-env switch-to dev

Or switch to the myprod environment:

flutter-env switch-to myprod

If you have set up Firebase as well, you need to aff the with-fb option:

flutter-env switch-to myprod --with-fb

flutter-env list

Lists the environments from the flutter-env.json file and prepend the current environment with a *.

flutter-env -h

Prints help message.

flutter-env flutter-env-example

Prints an example flutter-env.json file.