Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

dart

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?

like image 383
melmac Avatar asked Mar 19 '14 22:03

melmac


1 Answers

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

  • Configuring the Built-in dart2js Transformer
  • How to achieve precompiler directive like functionality
  • https://github.com/dart-lang/pub/issues/798
  • http://blog.sethladd.com/2013/12/compile-time-dead-code-elimination-with.html
  • https://api.dartlang.org/stable/1.22.0/dart-core/bool/bool.fromEnvironment.html
  • dart check if is building
like image 86
Günter Zöchbauer Avatar answered Sep 16 '22 22:09

Günter Zöchbauer