Hey there I am searching for a function which is printing a dynamic variable as completely as possible to the console in Dart language.
In PHP for i
There is no built in function that generates such an output.
print(variable)
prints variable.toString()
and Instance of 'FooBarObject'
is the default implementation. You can override it in custom classes and print something different.
You can use reflection (https://www.dartlang.org/articles/libraries/reflection-with-mirrors) to build a function yourself that investigates all kinds of properties of an instance and prints it the way you want. There is almost no limitation of what you can do and for debugging purposes it's definitely a fine option.
For production web application it should be avoided because it limits tree-shaking seriously and will cause the build output size to increase notable. Flutter (mobile) doesn't support reflection at all.
You can also use one of the JSON serialization packages, that make it easy to add serialization to custom classes and then print the serialized value. For example
I think there are others, but I don't know about (dis)advantages, because I usually roll my own using https://pub.dartlang.org/packages/source_gen
dart:developer library has inspect function that allows debuggers to open an inspector on the object.
To use it add:
import 'dart:developer';
And the you can see your inspected variable/object in console with:
inspect(myVar);