Table of Contents
Comments, Keywords, Variables in Dart
The concept of comments is the same in all programming languages. A comment is a code explanation. We explain our code through it. It is not part of the code. Comments help us when we type hundreds of codes or we are doing teamwork or going to review code. We can remember the logic behind code through comments even after years. Humans can forget their own written code so comments will help in resolving this issue. In freelancing a client can also give a code for a previous app so it is easy if comments are there to help. It’s like FB commenting and explaining the code. We can write comments anywhere even between functions. We can comment in Urdu or Roman as well.
Types of comments
Single line comments
It is written with two slashes and no space between // for example:
//This code will print Hello World.
Multi-line comments
More explanation is given in multi-line comments. There is no space in between * and / for example:
/*
We can write in between multiple lines.
*/
Documents comments:
It is used to explain the whole document with three slashes. It is on top and anyone can easily understand it. However, there is less use of it. The format is as under:
/// This document is for technical purposes.
How to print the Hello World program?
We can print “Hello World” in Dart with the following command:
void main (){
print (“Hello World”);
}
In the above statement, within the main structure of Dart, there is a print command, parenthesis, colon, and in double quotes our desired text.
It is important to remember that everything is in small cases. If we use this code, it will print as it is in the console. It shows in text form. We can also type in a single quote as well means ‘Hello World’. Dart is a case-sensitive language. We can also add some space or enter in our code so don’t forget to right-click and select “Reformat code with ‘dart format’ to bring in proper Dart format. We can print multiple statements in the same manner.
Keywords
There are specific keywords in every language. Similarly, we will use keywords in Dart and it has a purpose. We cannot use these words for our purpose.
Variables
The concept of variables is also the same in all programming languages. It is like a container used to store data and just like a box. We can put things in a container and similarly in Dart variables contain data. We can put any type of data for example text, Integer values, etc. in it. The variable can contain any type of data.
Types of Variables
There are multiple types but at this stage, we will learn the following:-
String
All our text data (phrases, paragraphs, etc.) can be shown in this type. The first letter of the keyword String i.e. S is capital.
Integer
The numeric values and whole numbers are in integer type and we use the int keyword.
Double
Fraction values mean 2.3, 4.4, etc. are in the double type and we use dual keywords. If we use integer values in double then there will be no issue as well.
Bool
True & False type data is contained in this variable type, and we use the bool keyword.
Important Options of Android Studio
When we open Android Studio on the first screen by clicking customize we can change its colour theme and font size. In the section on plugins, we can add them to enhance the functionality of Android Studio. As discussed in the last class at least install Dart and Flutter plugins. We can avoid other plugins if our PC/ laptop is slow. There are different shortcut keys in Android Studio. We can learn them to work easily and proficiently. The alternative to Android Studio is VS Studio. We need to learn any one of them. Both are good but we are learning Android Studio in this course. You can download Android Studio from here.
How to name a Project, file & folder
We will use small letters and underscore for naming. It is important to understand that we can give names in any format but we need to exercise best practices for professional work. These conventions/ standards are set by Dart. No numbers or special characters should be in the project name. Don’t mix hyphen – with underscore _ both are different. We will also give file, and folder names in the same manner.
Interface of Android Studio Project
There is a toolbox with left, right, up & down bar options. It is our ground to play. On the left top corner, there are Project files of dart/ flutter. We can click on the right sidebar to open or close windows. There is a bookmarks window, bottom bar, version control, etc. We need to use one at a time. The active bar would be on a grey background.
Project files, folder & enabling change font with mouse option
We have our main concern with project files and in main.dart file in it. We can maximize or minimize the zoom view in Android Studio with our mouse. For this, we need to go to settings from the file menu. Then select General in the editor and enable Change Font Size with the Ctrl+Mouse wheel.
Shortcuts
As discussed earlier, use the keyboard to do all the work. It is a sign of a good developer. If know shortcut keys on the keyboard then we can work quickly.