Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print multiple objects to console.log with dart?

Tags:

dart

dart-html

In javascript, if I have 3 variables like this:

var x = 1
var y = 'cat'
var z = {color: 'blue'}

I can log all of them like this:

console.log('The values are:', x, y, z)

In dart, you can import 'dart:html' and it will map print to console.log in the compiled javascript. But print only takes one parameter - not 3. This dart will fail when the compiled js runs in the browser:

print('The values are:', x, y, z)

The only thing I can think to do is stringify these arguments and join them into one string, and print that. But then I lose Chrome's ability to expand objects that are printed to the console.

Is it possible to print multiple objects with one print statement (or similar statement)? If so, how?

like image 750
cilphex Avatar asked Nov 05 '14 11:11

cilphex


People also ask

How do you print to console in darts?

If you simlpy want to print text to the console you can use print('Text') . But if you want to access the advanced fatures of the DevTools console you need to use the Console class from dart:html : Console. log('Text') . It supports printing on different levels (info, warn, error, debug).

How do you print a value in console in flutter?

you can simply use print('whatever you want to print') same as console. log() in javascript. for more info you can check here. Save this answer.

How do I print a long log in flutter?

Print Long String in console While developing flutter app The Right way to log data on console is by importing dart inbuilt package “dart:developer”, This allows a developer to print longs information on console while debugging. So to use developer. log function in flutter app you need to import it.


1 Answers

What about: ?

print('The values are: ${[x, y, z]}')

or

print('The values are: $x, $y, $z')

or

['The values are:', x, y, z].forEach(print);
like image 51
Günter Zöchbauer Avatar answered Sep 30 '22 12:09

Günter Zöchbauer