KEMBAR78
Flutter Lecture#01 | PDF | Boolean Data Type | Data Type
0% found this document useful (0 votes)
16 views10 pages

Flutter Lecture#01

Uploaded by

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

Flutter Lecture#01

Uploaded by

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

What is Flutter?

Flutter is an open-source UI software development kit (SDK) created by Google. It is used to


build natively compiled applications for mobile, web, and desktop from a single codebase.

Why Flutter?
#01 #02 #03 #04

01 Single Codebase: 02 Cross-Platform: 03 Layered Structure: 04 Easy & Fast:


• Write once, Run • Flutter is a cross • Flutter provides layered • Flutter is easy to
anywhere. platform Language. It Structure with several understand. It is best
means that you can customizable widgets. choice to start App
• Develop for iOS, write a flutter code development at
Android, web, desktop, once, and run in • Flutter’s framework is beginner level.
or linux OS. anywhere or any OS. written in C++,
provides low-level • The app created in
• Note: You can also rendering support. flutter is very fast with
handles you flutter smooth animation.
code differently on
different types of OS.

1
Flutter Project Structure

Auto Generated Files & Folders: 1 2


flutter_project
> .dart_tool
> .idea “.dart_tool:/” .idea/:
> android [flutter_project]
> ios Stores Dart-related dependencies and Contains project-specific settings
> lib tools required by Flutter. and configurations for IntelliJ-based
> linux It’s managed by Flutter and shouldn't IDEs (like Android Studio).
> macos be modified manually.
> test
> web
> windows
.gitignore 4 3
.metadata
analysis_options.yaml
flutter_project.iml
pubspec.lock
android/: ios/:
pubspec.yaml Contains the native Android code for Contains the native iOS code for
README.md running the Flutter app. running the Flutter app.
> External Libraries If you need to add platform-specific Useful when integrating native iOS
Scratches and Consoles code (Kotlin/Java), modify files here. functionalities using Swift/Objective-C.

2
Flutter Project Structure (directories)

5 6 7

lib/: linux:/ macos/:


The main folder where you write Contains the necessary files to run Contains macOS-specific files to build
Flutter application code (Dart files). the Flutter app on Linux desktop. and run the Flutter app on macOS.
The entry point of the app is typically
.

0 9 8

windows/: web/: test/:


Contains Windows-specific files to run Contains files for running the Flutter Used for writing unit and widget
the Flutter app on Windows desktop. app in a web browser. tests for your Flutter application.
Includes an index.html file that acts You can place test files here and run
as an entry point for web apps. them using flutter test.

3
Flutter Project Structure (Files)

1 2 3

.gitignore: .metadata: Analysis_option.yaml:


Specifies which files and folders Git Stores project-related metadata Used for setting linting rules and static
should ignore (e.g., .dart_tool/, build used internally by Flutter. analysis for Dart code.
files).

6 5 4

External Libraries, Scratch Files README.md: pubspace.yaml:


External Libraries: Dependencies and A markdown file where you can write The most important configuration
Dart packages used in the project. project documentation. file in a Flutter project.
Scratches and Consoles: Temporary Used to define dependencies, assets,
files or debug output from the IDE. fonts, and project information.

4
Defines the type of data that
Dart Data Types: can be stored in a variable

1 2 3
int double num

Data like: 23, -434, 0 Data like: 3.144147, -0.44 Both int+double

int: Represents integer values Double: Represents floating- num: Represents both integer
Ex1: int age=25 point values. or floating-point values.
Ex2: int iq=-100 Ex1: double pi=34.1417; Ex1: num x=10;
Ex2: double h=0.00001; Ex2: num y=3.14;

5
Dart Data Types: (#02)

1 2 3
bool String List

bool isRaining=true; String name=“Mudassar”; List<int> num=[1, 2, 3];

bool: Represents data like true, String: Represents a sequence List: is used when you need to
false. It can be used when you of characters. It can be enclosed handle ordered collection of
need to represents values that in single or double quotes. objects. It can be hold elements
can be true or false. It is most of the same or different types.
commonly used in conditional List<dynamic> i=[1, 0.1, true];
coding. 6
Dart Data Types: (#03)

1 2 3
dynamic Symbol Null

dynamic x=10; x=false; Symbol s=#mySymbol; int? x=null;

dynamic: A special type that Symbol: Represents an Null: Represents the absence of
can hold any value (disables operator or identifier declared a value. It is used where the
static type checking). in a dart program. It rarely used value can be null. It helps to
It can be useful where the type in every day programming. prevent null errors.
of the value can be change.
7
Non-Nullable Types Nullable Types
By default, variable cannot be null. Use ? Just after the data type for nullable

In dart, when you declare and initialize a In dart, if you need to declare a variable that
variable in program, it is necessary to assign any can be null, you can use “?” mark. It prevents
value. If you assign null to non-nullable type, from NullPointerException.
then you will face a NullPointerException.
For example:
For example: Int? age=25; //age can be nullable now.
int age=25; //this statement is correct. Such as:
int age; OR int age=null; int age=null;
The above (last) two statements are invalid print(“my age is: $age”);
because these statements assign null value to a
non-nullable type variable. So it cause The output of above statement will be.
NullPointerException exception. my age is: null;

8
Null-Aware Operator
• Safe navigation operator (access a
property only if the object is not
null).
Safe Navigation
? String? name;
print(name?.length); // Output: null

• Null-coalescing operator (provide a


default value if the variable is null).
?? Null-coalescing
int? x;
print(x ?? 1);//Output: 1

• Null assertion operator (assert that


a nullable variable is not null).
! Null Assertion
int? x = 10;
print(x! + 5);// Output:15
9
01 03
Null Safety in collections Summary Table
Collections like List, Set, and Map can also be
nullable or contain nullable elements.
Type Description
List<int?> numbers = [1, null, 3]; // List of int Integer values
nullable integers double Floating-point numbers
Map<String, int?> ages = {"Alice": 25, "Bob":
null}; // Map with nullable values num Can hold both “int” and “double”
String Text values
bool Boolean (true or false)
List<T> Ordered collection (Array)
Map<K, V> Key-value pair collection

Late Variable: 02 Set<T> Collection of unique elements


Null Special type that represents null
Use late to declare a variable that will be
initialized later (non-nullable but not immediately) var assigns type dynamically
dynamic Can hold any type, but unsafe.
late int x;
x = 10; // Must be initialized before use
10

You might also like