Menu
CoddyTech

Comments

Part of the Your First App section of Coddy's Flutter journey. Lesson 6 of 32.

A line that starts with two slashes is a comment. Dart skips everything after the //, to the end of the line:

// A greeting for the home screen
Text('Hello')

Comments are notes for the people reading the code. They are also handy for switching a line off without deleting it: put // in front of it, and take the slashes away to switch it back on.

A Center has only one child:. Giving it two is an error, and the app does not start.

challenge icon

Challenge

Easy

The app shows I am hidden. Under it is a line that is switched off with a comment. Swap them:

  • switch off the I am hidden line with //
  • switch on the I am visible line by removing its //

Try it yourself

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: Text('I am hidden'),
          // child: Text('I am visible'),
        ),
      ),
    );
  }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Your First App

Practice on your own: Online Flutter compiler