Check if running app is in Debug mode

Kevin Walter
:

I have a short question. I'm looking for a way to execute code in Flutter when the app is in Debug mode. Is that possible in Flutter? I can't seem to find it anywhere in the documentation.

Something like this

If(app.inDebugMode) {
   print("Print only in debug mode");
}
rmtmckenzie
:

While this works, using constants kReleaseMode or kDebugMode is preferable. See Rémi's answer below for a full explanation, which should probably be the accepted question.


The easiest way is to use assert as it only runs in debug mode.

Here's an example from Flutter's Navigator source code:

assert(() {
  if (navigator == null && !nullOk) {
    throw new FlutterError(
      'Navigator operation requested with a context that does not include a Navigator.\n'
      'The context used to push or pop routes from the Navigator must be that of a '
      'widget that is a descendant of a Navigator widget.'
    );
  }
  return true;
}());

Note in particular the () at the end of the call - assert can only operate on a boolean, so just passing in a function doesn't work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Detect Android App Is Running In Debug Mode

From Dev

How to determine that my iOS app is running in DEBUG mode?

From Dev

How to determine that my iOS app is running in DEBUG mode?

From Dev

Determine if a program is running in debug mode

From Dev

Check if program runs in Debug mode

From Dev

Check if program runs in Debug mode

From Dev

My Windows Store app is still running in debug mode after I close it

From Dev

ASP.NET 5 web app not running in debug mode in IIS Express

From Dev

AsyncTaskRunner in debug mode exits the app?

From Dev

Check if grunt is running in verbose mode

From Dev

Running Autoprefixer with BundleTransformer / LESS in Debug mode

From Dev

Program running in debug mode in C::B only

From Dev

Running Autoprefixer with BundleTransformer / LESS in Debug mode

From Dev

Freeradius running debug mode libssl version mismatch

From Dev

Is the running speed of a program related to Debug mode or Release mode?

From Java

Android app crashes when launched in debug mode

From Dev

IntelliJ IDEA 13.0 constant debug mode for app?

From Dev

How to run Dropwizard app in debug mode with Eclipse?

From Dev

Android - app icon for debug and release mode

From Dev

Python App Engine debug/dev mode

From Dev

How to debug app in compatibility mode on iOS 7?

From Dev

Different language for debug and release mode in iOS app?

From Dev

Android Studio App only Debug-Mode

From Dev

IntelliJ IDEA 13.0 constant debug mode for app?

From Dev

Implications of leaving a system app in debug mode?

From Dev

Running app in Debug via Xcode vs running app manually

From Dev

Check app running on new port

From Dev

Running different App class in my application (for debug)

From Dev

Skip Ansible task when running in check mode?

Related Related

  1. 1

    Detect Android App Is Running In Debug Mode

  2. 2

    How to determine that my iOS app is running in DEBUG mode?

  3. 3

    How to determine that my iOS app is running in DEBUG mode?

  4. 4

    Determine if a program is running in debug mode

  5. 5

    Check if program runs in Debug mode

  6. 6

    Check if program runs in Debug mode

  7. 7

    My Windows Store app is still running in debug mode after I close it

  8. 8

    ASP.NET 5 web app not running in debug mode in IIS Express

  9. 9

    AsyncTaskRunner in debug mode exits the app?

  10. 10

    Check if grunt is running in verbose mode

  11. 11

    Running Autoprefixer with BundleTransformer / LESS in Debug mode

  12. 12

    Program running in debug mode in C::B only

  13. 13

    Running Autoprefixer with BundleTransformer / LESS in Debug mode

  14. 14

    Freeradius running debug mode libssl version mismatch

  15. 15

    Is the running speed of a program related to Debug mode or Release mode?

  16. 16

    Android app crashes when launched in debug mode

  17. 17

    IntelliJ IDEA 13.0 constant debug mode for app?

  18. 18

    How to run Dropwizard app in debug mode with Eclipse?

  19. 19

    Android - app icon for debug and release mode

  20. 20

    Python App Engine debug/dev mode

  21. 21

    How to debug app in compatibility mode on iOS 7?

  22. 22

    Different language for debug and release mode in iOS app?

  23. 23

    Android Studio App only Debug-Mode

  24. 24

    IntelliJ IDEA 13.0 constant debug mode for app?

  25. 25

    Implications of leaving a system app in debug mode?

  26. 26

    Running app in Debug via Xcode vs running app manually

  27. 27

    Check app running on new port

  28. 28

    Running different App class in my application (for debug)

  29. 29

    Skip Ansible task when running in check mode?

HotTag

Archive