Skip to content

Instantly share code, notes, and snippets.

@apaatsio
Created March 19, 2019 12:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apaatsio/0aa9389b7db61f346828c35ca4f0412b to your computer and use it in GitHub Desktop.
Save apaatsio/0aa9389b7db61f346828c35ca4f0412b to your computer and use it in GitHub Desktop.
Helper utility to detect build mode (debug, profile, and release) in a Flutter app.
abstract class BuildMode {
static final BuildModeType buildMode = () {
if (const bool.fromEnvironment('dart.vm.product')) {
return BuildModeType.release;
}
var result = BuildModeType.profile;
assert(() {
result = BuildModeType.debug;
return true;
}());
return result;
}();
static final bool isDebug = buildMode == BuildModeType.debug;
static final bool isNotDebug = !isDebug;
static final bool isProfile = buildMode == BuildModeType.profile;
static final bool isNotProfile = !isProfile;
static final bool isRelease = buildMode == BuildModeType.release;
static final bool isNotRelease = !isRelease;
}
enum BuildModeType {
debug,
profile,
release,
}
import './build_mode.dart';
print('App is running in ${BuildMode.buildMode}');
if(BuildMode.isRelease) {
initializeAnalytics();
}
if(BuildMode.isDebug) {
print('Some debugging info.');
// Note: to print debug info, check out also debugPrint() as an alternative
// See https://flutter.dev/docs/testing/debugging#print-and-debugprint-with-flutter-logs
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment