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

Any ideas how I can configure the Dart application to use different settings in debug mode (works in Dartium) and in production mode?

For example, I use PouchDb in my application, which replicates the database to a specific CouchDb instance with the specified URL: db.replicateTo(url); In debug mode, I would like to use a different instance of CouchDb (different URL) than in production mode.

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

+4
source share
1 answer

this works after a while:

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

access it from code for example

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

+8

Source: https://habr.com/ru/post/1532569/


All Articles