Often the development and deployment environments are different. For example, the app has to connect to a different database or a different mail server in either environment to use a mocked service in development and the real service in production, or something like that. How can we use different setups in both modes, or achieve a kind of precompiler directive-like functionality?
Perform the following steps to use different settings:
Add a transformers section to
pubspec.yaml
with an environment line that specifies a map of the settings, names and values, as follows (see the code indev_prod_settings
):transformers: # or dev_transformers - $dart2js: environment: {PROD: "true", DB: "MongoPROD"}
You can, for example, get the value of the DB setting from
const String.fromEnvironment('DB')
, as you can see in the following code:import 'dart:html'; void main() { print('PROD: ${const String.fromEnvironment('PROD...