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?
Asked
Active
Viewed 424 times
2 Answers
3
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
}

Aman Gupta
- 211
- 2
- 7
2
You can use assert
which only works in debug mode.
assert(() {
// This block only runs in debug mode.
return true;
}());

CopsOnRoad
- 237,138
- 77
- 654
- 440
-
[This answer](https://stackoverflow.com/a/64118075/6618622) also provides other ways of checking it. – CopsOnRoad Sep 10 '22 at 08:01