0% found this document useful (0 votes)
5 views

CS31-AppDev_Module 1

This document introduces Dart, a programming language developed by Google for building various types of applications, particularly with the Flutter framework. It outlines objectives for learning Dart, including writing programs, using variables, control flow statements, and importing libraries. Additionally, it provides a brief overview of Dart's features, such as variable declaration, functions, comments, and user input handling.

Uploaded by

Xander Pardico
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

CS31-AppDev_Module 1

This document introduces Dart, a programming language developed by Google for building various types of applications, particularly with the Flutter framework. It outlines objectives for learning Dart, including writing programs, using variables, control flow statements, and importing libraries. Additionally, it provides a brief overview of Dart's features, such as variable declaration, functions, comments, and user input handling.

Uploaded by

Xander Pardico
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

CS31-AppDev (Application Development and Emerging Technologies)

College of Computer Studies

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.

III. PRELIM INARY ACTIVITIES


N/A

IV. LESSON PROPER


This module provides a brief introduction to the Dart language through samples of its main features.

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.

E. Control Flow statements


Just like any other programming language Dart also supports our usual control flow statements:

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

I. Standard input and Output


In order for us to take an input from the user we must first import the “dart:io” in our project.

A. String user input


They are used for storing textual user input. If you want to keep values like somebody’s name, address,
description, etc., you can take string input from the user.

B. Integer User input


You can take integer input to get a numeric value from the user without the decimal point. E.g., 10, 100, -
800 etc.

C. Floating point user input


You can use float input if you want to get a numeric value from the user with the decimal point. E.g., 10.5,
100.5, -800.9 etc.

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.

Calculate the shipping cost according to these conditions:


If the destination zone is 'MAR' The shipping cost is 280 pesos per Kilogram.
If the destination zone is 'MEYC' The shipping cost is 392 pesos per Kilogram.
If the destination zone is 'SJDM' The shipping cost is 560 pesos per Kilogram.
If the destination zone is not the following, display an error message.

The program must also ask the user if they want to try again and ask for another computation, else the
program will end.

VI. ADDITIONAL RESOURCES


N/A
VII. ASSESSMENT
N/A

VIII. REFERENCES
 https://dart.dev/guides

 https://dart-tutorial.com/introduction-and-basics/user-input-in-
dart/

Page 6 of 6

You might also like