CS31-AppDev_Module 1
CS31-AppDev_Module 1
I. INTRODUCTION
Dart is a client-optimized programming language
developed by Google, it is primarily used for
building mobile application, desktop, server, and
web application.
It is known for its use in flutter, a popular
Module 1 framework for creating natively compiled
applications for android, ios, and desktop from a
Introduction to Dart single codebase.
II. OBJECTIVES
1. Write and execute Dart programs
2. Declare and use variables with and
without explicit type annotations,
leveraging Dart's type inference.
3. Implement and manage basic control
flow statements including if-else
conditions, for loops, and while loops.
4. Effectively use Dart comments to
document code and understand the
different types of comments supported.
5. Import and utilize external libraries and
packages to extend the functionality of
Dart applications.
A. Hello World
Every app requires the top-level main() function, where execution starts. Functions that don't explicitly
return a value have the void return type. To display text on the console, you can use the top-
level print() function:
Page 1 of 6
CS31-AppDev (Application Development and Emerging Technologies)
College of Computer Studies
B. Variable
The Dart language is type safe it means that it uses a combination of static type checking and runtime
checking to ensure that a variable’s value always matches the variable’s static type, sometimes referred to as
sound typing.
You can declare most variables without explicitly specifying their type using var. Thanks to type inference,
these variables’ types are determined by their initial values:
But, just like other programming languages, you could also follow this declaration “<datatype> <variable
name> = <value>;”. Declaring the following data types which are String, Integer, Double, Float, Char, with
addition of dynamic datatype. There are various ways of declaring a variable:
C. Var/Dynamic
You could use the var and dynamic keyword in declaring a variable. Using var and dynamic keyword means
that the data type of the object will be based on the initial value of the object by its runtime. But you need to
keep in mind that using the dynamic keyword means that you could change the value of the object even if
those objects are not similar in term of data type on the other hand, using var you don’t have that kind of
privilege.
Page 2 of 6
CS31-AppDev (Application Development and Emerging Technologies)
College of Computer Studies
D. Var/Final/Const
You could also use these 3 to declare your variables instead of their datatypes. “<var/final/const>
<variable name> = <value>;”.
Var – The var keyword is used to infer the data type of the variable based on the initial value.
Final – The final keyword is used to define a constant whose values are not known at runtime.
Const – The const keyword is used to define a constant whose values are known at runtime.
Both const and final keywords define identifiers that can be assigned once and their values will not be changed
throughout the program.
Page 3 of 6
CS31-AppDev (Application Development and Emerging Technologies)
College of Computer Studies
F. Functions
Dart also supports functions. But just like other programming language, Dart wants you to specify each
function’s argument and return type.
You could also write a function using the short-hand “=>”. A shorthand => (arrow) syntax is handy for
functions that contain a single statement. This syntax is especially useful when passing anonymous functions as
arguments:
Besides showing an anonymous function (the argument to where()), this code shows that you can use a
function as an argument: the top-level print() function is an argument to forEach().
G. Comments
Dart comments usually start with //. But you could also make use of “/*” and “*/”.
H. Imports
To access APIs defined in other libraries, use import. The major import that we almost will always use is
the “import: dart.io” for it is used for the standard input and output of dart.
Page 4 of 6
CS31-AppDev (Application Development and Emerging Technologies)
College of Computer Studies
Page 5 of 6
CS31-AppDev (Application Development and Emerging Technologies)
College of Computer Studies
V. PRACTICE
EXERCISES/ACTIVITIES Exercises:
Develop a program to calculate the shipping cost based on the destination zone and the weight of the
package.
The program must also ask the user if they want to try again and ask for another computation, else the
program will end.
VIII. REFERENCES
https://dart.dev/guides
https://dart-tutorial.com/introduction-and-basics/user-input-in-
dart/
Page 6 of 6