diff --git a/packages/flutter/lib/src/foundation/constants.dart b/packages/flutter/lib/src/foundation/constants.dart index cd9b40c6a3..fc56a0cc6d 100644 --- a/packages/flutter/lib/src/foundation/constants.dart +++ b/packages/flutter/lib/src/foundation/constants.dart @@ -11,3 +11,23 @@ /// a particular block of code will not be executed in release mode, and hence /// can be removed. const bool kReleaseMode = bool.fromEnvironment('dart.vm.product', defaultValue: false); + +/// A constant that is true if the application was compiled in profile mode. +/// +/// More specifically, this is a constant that is true if the application was +/// compiled in Dart with the '-Ddart.vm.profile=true' flag. +/// +/// Since this is a const value, it can be used to indicate to the compiler that +/// a particular block of code will not be executed in profle mode, an hence +/// can be removed. +const bool kProfileMode = bool.fromEnvironment('dart.vm.profile', defaultValue: false); + +/// A constant that is true if the application was compiled in debug mode. +/// +/// More specifically, this is a constant that is true if the application was +/// not compiled with '-Ddart.vm.product=true' and '-Ddart.vm.profile=true'. +/// +/// Since this is a const value, it can be used to indicate to the compiler that +/// a particular block of code will not be executed in debug mode, and hence +/// can be removed. +const bool kDebugMode = !kReleaseMode && !kProfileMode; diff --git a/packages/flutter/lib/src/widgets/implicit_animations.dart b/packages/flutter/lib/src/widgets/implicit_animations.dart index a222be5340..d9868f590e 100644 --- a/packages/flutter/lib/src/widgets/implicit_animations.dart +++ b/packages/flutter/lib/src/widgets/implicit_animations.dart @@ -280,7 +280,7 @@ abstract class ImplicitlyAnimatedWidgetState super.initState(); _controller = AnimationController( duration: widget.duration, - debugLabel: '${widget.toStringShort()}', + debugLabel: kDebugMode ? '${widget.toStringShort()}' : null, vsync: this, ); _updateCurve(); diff --git a/packages/flutter/lib/src/widgets/scroll_activity.dart b/packages/flutter/lib/src/widgets/scroll_activity.dart index 305489999b..778456ef97 100644 --- a/packages/flutter/lib/src/widgets/scroll_activity.dart +++ b/packages/flutter/lib/src/widgets/scroll_activity.dart @@ -507,7 +507,7 @@ class BallisticScrollActivity extends ScrollActivity { TickerProvider vsync, ) : super(delegate) { _controller = AnimationController.unbounded( - debugLabel: '$runtimeType', + debugLabel: kDebugMode ? '$runtimeType' : null, vsync: vsync, ) ..addListener(_tick) diff --git a/packages/flutter/lib/src/widgets/ticker_provider.dart b/packages/flutter/lib/src/widgets/ticker_provider.dart index 57db697b0a..06d1364720 100644 --- a/packages/flutter/lib/src/widgets/ticker_provider.dart +++ b/packages/flutter/lib/src/widgets/ticker_provider.dart @@ -90,7 +90,7 @@ mixin SingleTickerProviderStateMixin on State imple 'mixing in a SingleTickerProviderStateMixin, use a regular TickerProviderStateMixin.' ); }()); - _ticker = Ticker(onTick, debugLabel: 'created by $this'); + _ticker = Ticker(onTick, debugLabel: kDebugMode ? 'created by $this' : null); // We assume that this is called from initState, build, or some sort of // event handler, and that thus TickerMode.of(context) would return true. We // can't actually check that here because if we're in initState then we're diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart index 068d1415ac..4768aae656 100644 --- a/packages/flutter_tools/lib/src/compile.dart +++ b/packages/flutter_tools/lib/src/compile.dart @@ -281,8 +281,12 @@ class KernelCompiler { command.add('--aot'); command.add('--tfa'); } + // If we're not targeting product (release) mode and we're still aot, then + // target profile mode. if (targetProductVm) { command.add('-Ddart.vm.product=true'); + } else if (aot) { + command.add('-Ddart.vm.profile=true'); } if (incrementalCompilerByteStorePath != null) { command.add('--incremental');