I used to do this CPP, to debug my code quickly.
code.cpp:
#define bug(x) cout << #x << ": " << x << '\n'
int main() {
    int a = 5;
    bug(a);
    int b = 3;
    bug(b);
    
    return 0;
}
output:
a: 5
b: 3
what this does is, it print the variable name along with it's value dynamically.
now I am trying to make something like this in dart, but couldn't find anything.
can such thing be even done in dart ?? btw, if you a better debug practice, please let me know :)
I searched on StackOverflow, but couldn't find anything:
- Get Variables name by it's value in Dart Lang:
- the answer mentioned only prints the value from a map, but what I am asking is to print the variable name itself (a,b) along their value (5,3)
- and using reflectableprints the variable name by passing value, but I simply want to print variable name by passing variable itself.
 
- the answer mentioned only prints the value from a map, but what I am asking is to print the variable name itself (
I even asked ChatGPT, but this is what it came up with:
void bug(var x) {
  print('$x: ${x.toString()}');
}
void main() {
  int x = 5;
  bug(x);
}
not useful at all :facepalm:, as this will print 5: 5.
