melmac melmac -4 years ago 160
Dart Question

Dart: How to use different settings in debug and production mode?

Are there any ideas how I can setup my Dart app to use different settings in debug mode (running in Dartium) and production mode?

For example, I'm using PouchDb in my app, that replicates the database to a particular CouchDb instance, given by an url:

db.replicateTo(url);

In debug mode, I would like to use another CouchDb instance (another url) than in production mode.

So, are there any ideas or approaches, to use different setups in both modes?

Answer Source

this works since a short while:

transformers: # or dev_transformers
- $dart2js:
  environment: { PROD: "true" }

access it from the code like

String.fromEnvironment()

main() {
  print('PROD: ${const String.fromEnvironment('PROD')}'); 
  // works in the browser
  // prints 'PROD: null' in Dartium
  // prints 'PROD: true' in Chrome
}

see also

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download