Book Image

DART Cookbook

By : Ivo Balbaert
Book Image

DART Cookbook

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Dart Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using different settings in the checked and production modes


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?

How to do it...

Perform the following steps to use different settings:

  1. 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 in dev_prod_settings):

    transformers: # or dev_transformers
    - $dart2js:
          environment: {PROD: "true", DB: "MongoPROD"}
    
  2. 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...