10 C
New York
Monday, November 27, 2023

How to make Comments in Flutter & Dart

This is a concise article about commenting in Flutter and Dart.

Single-Line Comment (Format Comment)

Just put two slash symbols at the beginning of the line you want to comment out.Advertisements

// This is a comment

Multi-Line Comment (Block Comment)


/* ... */

This method is usually used to comment out a block of code, like this:

class HomeScreen extends StatelessWidget {
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Kindacode.com'),
      body: Center(),

DOC Comment

Using DOC comment allows the dartdoc library to automatically generate documentation for your code based on the content of your comments.


/// Deletes the file at [path].
/// Throws an [IOError] if the file could not be found. 

Using hot keys in Visual Studio Code

If you are using Visual Studio Code, you can comment out a single line or a block of code by using keyboard shortcuts. Just select the lines you want to make comment with your mouse, then press the following key combination:

  • Ctrl + K then press Ctrl + C if you’re using Windows
  • Command + K then press Command + C if you’re on a Mac

To uncomment a block of code, use your mouse to select it and then use the following key combination:

  • Ctrl + K then Ctrl + U if you’re on Windows
  • Command + K then Command + U if you’re on a Mac

You can also hit Ctrl + / (Windows), Command + / (Mac) to toggle comments.


That’s it. To learn more about Flutter and Dart, read also:

You can also check out our Flutter category page or Dart category page for the latest tutorials and examples.

Related Articles

Latest Articles