MANISH
MANISH

Reputation: 3348

Flutter : How to you execute code only in debug mode in Flutter?

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?

Upvotes: 3

Views: 1781

Answers (2)

Aman Gupta
Aman Gupta

Reputation: 271

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
}

Upvotes: 5

CopsOnRoad
CopsOnRoad

Reputation: 268504

You can use assert which only works in debug mode.

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

  return true;
}());

Upvotes: 2

Related Questions