3

I am using Flutter and I want to perform a specific task only in debug mode How I can execute code only in debug mode?

2 Answers 2

6

Flutter provides kDebugMode which checks whether the app is running in debug mode or not. So you can execute the code just in the debug mode by just wrapping your desired code with the condition like this:

if (kDebugMode) {
  // your desired code
}
Sign up to request clarification or add additional context in comments.

Comments

2

You can use assert which only works in debug mode.

assert(() {
  // This block only runs in debug mode.

  return true;
}());

1 Comment

This answer also provides other ways of checking it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.