Chapter - 3 - Basics of Dart and Flutter
Chapter - 3 - Basics of Dart and Flutter
The above code show he sample dart program to print text Hello, CS IT SE!
Dart comment
Dart supports single-line comments, which start with //, and multi-line comments, enclosed within /* and
*/, providing flexibility in documenting different parts of the code.
➢ Numbers
int represents integer values, which are whole numbers without a decimal point. Example: 7, 5, -10.
double represents floating-point numbers, which are numbers that can have a fractional part. Example:
3.14, -2.7, 0.0.
➢ Strings
String represents a sequence of characters. Strings are used to store text. Example: "Hello, Dart!".
➢ Booleans
bool represents a Boolean value, which can be either true or false.
➢ Lists
List represents an ordered collection of items, also known as an array in other languages.
Example: List<String> fruits = ['Apple', 'Banana', 'Cherry'];.
➢ Sets
Set represents a collection of unique items, meaning no duplicate values are allowed.
Example: Set<int> numbers = {1, 2, 3, 4, 5};
➢ Records
Record introduced in Dart 3.0; records are a way to group multiple related values without creating a full
class. They are simple data structures. Example: var record = (name: 'Alice', age: 30);.
➢ Maps
Map: Represents a collection of key-value pairs, where each key is unique. Maps are useful for storing
associative arrays or dictionaries.
void main() {
//sinle line comment
print('Hello, CS IT SE!');
/* multi line comment
hi cs
hi IT
hi SE
*/
//number
int num1 = 10;
print(num1);//10
double num2 = 10.50;
print(num2);//10.5
//string
String name = 'CS_IT_SE';
print(name);//CS_IT_SE
//boolean
bool isTrue = true;
print(isTrue);//true
//list
List<int> list = [1, 2, 3, 4, 5];
print(list);//[1, 2, 3, 4, 5]
List department = ['CS', 'IT', 'SE'];
print(department);//[CS, IT, SE]
//set
Set<int> intSet = {1, 2, 3, 4, 5};
print(intSet);//{1, 2, 3, 4, 5}
Read https://dart.dev/language
<<Lab Task 2>>
3.2 Introduction to Flutter
Flutter is a mobile app development framework that enables developers to create high-quality, visually
appealing, and performant mobile applications for Android and iOS platforms. With Flutter, developers
can write code once and use it to build apps that look and feel native on multiple platforms. Flutter used
to develop cross-platform applications from a single codebase, meaning you can write one set of code
and deploy it to both iOS and Android devices. It uses the Dart programming language, which is known
for its fast performance and flexibility. The Flutter framework provides a rich set of pre-designed widgets
that allow developers to create beautiful and responsive user interfaces with ease.
Flutter, first introduced in 2015, and officially released in May 2017. Since its release, it has rapidly
gained popularity among developers for its ability to create high-quality, natively compiled applications
for mobile, web, and desktop from a single codebase. This versatile framework has continued to evolve,
driven by a robust community and support from Google, making it a go-to choose for cross-platform
development.
3.3 Why Flutter?
Flutter is not the only way for mobile application development. But at this time most developer like this
cross platform mobile application development. The reasons why it is selected are highlighted below.
Windows
This directory contains native Windows-specific files for building the app on Windows platform. It
COMPILED BY TADESSE SHEFERA 7
used for Modify for Windows-specific functionality.
.gitignore
It used for Specifying which files and directories Git should ignore. Add files (like build artifacts) that
shouldn't be version-controlled.
.metadata
Automatically generated and managed. Tracks metadata about the Flutter project (e.g., SDK version).
analysis_options.yaml
It customizes the Dart analyzer's behavior for linting and static code analysis. And add rules to enforce
coding standards.
pubspec.lock
It records the exact versions of dependencies used in the project. It automatically updated when pub get
is run.
pubspec.yaml
this file is used or configuration file for the Flutter project. it has key sections dependency which Lists
the packages used by the app and flutter which declares assets, fonts, etc. The pubspc.yaml used to
modify to add/remove packages or resources.
README.md
This file contains documentation about the project. And used for add details about the project, its setup,
and usage.
3.5.1 Widgets
Flutter emphasizes widgets as a unit of composition. Widgets are the building blocks of a Flutter app's
user interface, and each widget is an immutable declaration of part of the user interface. Widgets form a
hierarchy based on composition. Each widget nests inside its parent and can receive context from the
parent.
Widget composition
➢ The Navigator widget displays screens as a stack using the correct transition animations for the
target platform
➢ To navigate to a new screen, access the Navigator through the route's BuildContext and call
imperative methods such as push() or pop().
Using the Router