Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 275
MANISH Avatar asked Jul 08 '26 19:07

MANISH


2 Answers

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
}
like image 105
Aman Avatar answered Jul 10 '26 08:07

Aman


You can use assert which only works in debug mode.

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

  return true;
}());
like image 45
CopsOnRoad Avatar answered Jul 10 '26 10:07

CopsOnRoad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!