Flutter operating environment identity

Flutter four operating modes: Debug, Release, Profile and test, in the actual development, we often need to run depending on the current mode, choose different actions, such as enabling Log in Debug mode, the production mode off Log.
  If you are an Android developer, is certainly no stranger to this, in Android, there is a mode of operation to determine the current configuration according to BuildConfig class gradle automatically generated. Similarly, in the Flutter there is also a method to judge, we need to use dart.vm.product environmental flag, specific use:

const bool inProduction = const bool.fromEnvironment("dart.vm.product");

  When operating in the Release App environment, inProduction is true; when operating at App Profile and Debug Environment, inProduction to false.
    Release: const bool.fromEnvironment ( "dart.vm.product") = to true;
    the Debug: Assert (() {...; return to true;}); assertion statements are executed;
    Profile <br>: The above two cases are not will happen.

Guess you like

Origin www.cnblogs.com/loaderman/p/11564334.html