Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fully dump / print a variable to console in Flutter?

This is a follow-up to this Dart question.

Since Flutter doesn't support reflection and we can't use mirrors, how would you go about debugging, let's say an instance of firebase_database DatabaseReference ? I'm trying to write tests, and knowing what key/values my reference contains will make it easier for me to write a proper test.

like image 868
Adrien Lemaire Avatar asked Nov 29 '17 00:11

Adrien Lemaire


2 Answers

since Dart 3.12 you can use inspect(object) to achieve this

like image 56
omidh Avatar answered Sep 21 '22 02:09

omidh


If you expect to have a built-in easy solution, then sorry : You can't.

BUT you can use plugins to serialize your own code, such as built_value. And print the serialized object.

On the other hand, if you want to print external code (DatabaseReference for instance), you'll have to manually transform that object in a combination of Map, List, and int/String/double.

like image 35
Rémi Rousselet Avatar answered Sep 21 '22 02:09

Rémi Rousselet