Step By Step Tutorial in Learning Flutter: Lesson 9 — How to Add Comment

Misterflutter
2 min readMay 28, 2020

--

In this tutorial, we will discuss what are the benefits of adding a comment to your code then we will give examples on how to add comment in Flutter.

What are the benefits of adding comments:

  1. Readability. Communicate what the code is all about. It may be clear to you today, as the days passed you will tend to forget what the portion of code is all about. It would be easier if you add comment saving time in the future instead of trying to decipher all the lines of codes again.
  2. Shows respect to the next developer. Do unto others as you would have them do unto you. Imagine if you just joined a company and you inherit the code of the previous developer, would it be nice if there are comments written in plain human readable form? So, be respectful to others and when it is your turn to leave, it will be a nice turn over to the next developer.
  3. You can generate code documentation with comments. In most cases, your line manager will require you to document your code. Using comment will lessen the amount of hours documenting from scratch. While you are coding, why not put document comments on the spot so you don’t double work. You be more effective and productive.

There are different ways on how to add comment in Flutter

  1. The use of // in front of the code or line
// Our Main Screen that holds the menus or items.
class MainScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {

2. The use of /* */

You will use this comment if you require multiple lines

return MaterialApp(
title: 'Flutter',
/* Start the app with the "/" named route. In this case, the app
starts on the MainScreen widget. */

initialRoute: '/',
routes: {

3. The use of Doc Comments using ///

Doc comments are especially handy because dartdoc parses them and generates beautiful doc pages from them. A doc comment is any comment that appears before a declaration and uses the special /// syntax that dartdoc looks for.

/// Add the file at [path] from the file system.
void add(String path) {
...
}

There you have it, we have covered the benefits of adding comment to your Flutter code and we also discussed the different ways on how to add comment to your Flutter code.

Until next time :)

--

--

Misterflutter
Misterflutter

Written by Misterflutter

The best free step by step online course in learning Flutter. Learn how to develop iOS or Android app through easy to follow instruction tutorials with images.

No responses yet