whenEnv method

Future<void> whenEnv(
  1. String env, {
  2. required Function 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

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

  await perform();

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