whenEnv method

dynamic whenEnv(
  1. String env, {
  2. required dynamic perform(),
  3. bool shouldSetState = true,
})

Perform an action when the application's env is in a certain state

E.g. Inside in your .env file your APP_ENV='production' Call the method like the below example.

whenEnv('production', perform: () { .. perform any action you need to in production });

Implementation

whenEnv(String env,
    {required Function() perform, bool shouldSetState = true}) async {
  if (getEnv('APP_ENV') != env) {
    return;
  }

  if (perform is Future) {
    await perform();
  } else {
    perform();
  }

  if (shouldSetState) {
    setState(() {});
  }
}