| 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | /// @docImport 'platform.dart'; |
| 6 | library; |
| 7 | |
| 8 | /// A constant that is true if the application was compiled in release mode. |
| 9 | /// |
| 10 | /// More specifically, this is a constant that is true if the application was |
| 11 | /// compiled in Dart with the '-Ddart.vm.product=true' flag. |
| 12 | /// |
| 13 | /// Since this is a const value, it can be used to indicate to the compiler that |
| 14 | /// a particular block of code will not be executed in release mode, and hence |
| 15 | /// can be removed. |
| 16 | /// |
| 17 | /// Generally it is better to use [kDebugMode] or `assert` to gate code, since |
| 18 | /// using [kReleaseMode] will introduce differences between release and profile |
| 19 | /// builds, which makes performance testing less representative. |
| 20 | /// |
| 21 | /// See also: |
| 22 | /// |
| 23 | /// * [kDebugMode], which is true in debug builds. |
| 24 | /// * [kProfileMode], which is true in profile builds. |
| 25 | const bool kReleaseMode = bool.fromEnvironment('dart.vm.product' ); |
| 26 | |
| 27 | /// A constant that is true if the application was compiled in profile mode. |
| 28 | /// |
| 29 | /// More specifically, this is a constant that is true if the application was |
| 30 | /// compiled in Dart with the '-Ddart.vm.profile=true' flag. |
| 31 | /// |
| 32 | /// Since this is a const value, it can be used to indicate to the compiler that |
| 33 | /// a particular block of code will not be executed in profile mode, an hence |
| 34 | /// can be removed. |
| 35 | /// |
| 36 | /// See also: |
| 37 | /// |
| 38 | /// * [kDebugMode], which is true in debug builds. |
| 39 | /// * [kReleaseMode], which is true in release builds. |
| 40 | const bool kProfileMode = bool.fromEnvironment('dart.vm.profile' ); |
| 41 | |
| 42 | /// A constant that is true if the application was compiled in debug mode. |
| 43 | /// |
| 44 | /// More specifically, this is a constant that is true if the application was |
| 45 | /// not compiled with '-Ddart.vm.product=true' and '-Ddart.vm.profile=true'. |
| 46 | /// |
| 47 | /// Since this is a const value, it can be used to indicate to the compiler that |
| 48 | /// a particular block of code will not be executed in debug mode, and hence |
| 49 | /// can be removed. |
| 50 | /// |
| 51 | /// An alternative strategy is to use asserts, as in: |
| 52 | /// |
| 53 | /// ```dart |
| 54 | /// assert(() { |
| 55 | /// // ...debug-only code here... |
| 56 | /// return true; |
| 57 | /// }()); |
| 58 | /// ``` |
| 59 | /// |
| 60 | /// See also: |
| 61 | /// |
| 62 | /// * [kReleaseMode], which is true in release builds. |
| 63 | /// * [kProfileMode], which is true in profile builds. |
| 64 | const bool kDebugMode = !kReleaseMode && !kProfileMode; |
| 65 | |
| 66 | /// The epsilon of tolerable double precision error. |
| 67 | /// |
| 68 | /// This is used in various places in the framework to allow for floating point |
| 69 | /// precision loss in calculations. Differences below this threshold are safe to |
| 70 | /// disregard. |
| 71 | const double precisionErrorTolerance = 1e-10; |
| 72 | |
| 73 | /// A constant that is true if the application was compiled to run on the web. |
| 74 | /// |
| 75 | /// See also: |
| 76 | /// |
| 77 | /// * [defaultTargetPlatform], which is used by themes to find out which |
| 78 | /// platform the application is running on (or, in the case of a web app, |
| 79 | /// which platform the application's browser is running in). Can be overridden |
| 80 | /// in tests with [debugDefaultTargetPlatformOverride]. |
| 81 | /// * [dart:io.Platform], a way to find out the browser's platform that is not |
| 82 | /// overridable in tests. |
| 83 | const bool kIsWeb = bool.fromEnvironment('dart.library.js_util' ); |
| 84 | |
| 85 | /// A constant that is true if the application was compiled to WebAssembly. |
| 86 | /// |
| 87 | /// See also: |
| 88 | /// |
| 89 | /// * [defaultTargetPlatform], which is used by themes to find out which |
| 90 | /// platform the application is running on (or, in the case of a web app, |
| 91 | /// which platform the application's browser is running in). Can be overridden |
| 92 | /// in tests with [debugDefaultTargetPlatformOverride]. |
| 93 | /// * [dart:io.Platform], a way to find out the browser's platform that is not |
| 94 | /// overridable in tests. |
| 95 | const bool kIsWasm = bool.fromEnvironment('dart.tool.dart2wasm' ); |
| 96 | |