Console.log in Dart Language
How can I log into the browser console, like console.log
in JavaScript, from the Dart language?
Solution 1:
Simple:
print('This will be logged to the console in the browser.');
A basic top-level print
function is always available in all implementations of Dart (browser, VM, etc.). Because Dart has string interpolation, it's easy to use that to print useful stuff too:
var a = 123;
var b = Point(2, 3);
print('a is $a, b is ${b.x}, ${b.y}');
Solution 2:
Also, dart:html
allows use of window.console
object.
import 'dart:html';
void main() {
window.console.debug("debug message");
window.console.info("info message");
window.console.error("error message");
}