Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Lesson2 - Dart Object Oriented Programming.pptx

The document provides an overview of Object-Oriented Programming concepts in Flutter, including classes, objects, inheritance, polymorphism, encapsulation, and null safety. It explains how to declare classes and objects, the role of constructors, getters, and setters, as well as the significance of null safety in Dart. Additionally, it covers the use of the late keyword and type promotion in managing variable nullability.

Uploaded by

Loki Legends
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lesson2 - Dart Object Oriented Programming.pptx

The document provides an overview of Object-Oriented Programming concepts in Flutter, including classes, objects, inheritance, polymorphism, encapsulation, and null safety. It explains how to declare classes and objects, the role of constructors, getters, and setters, as well as the significance of null safety in Dart. Additionally, it covers the use of the late keyword and type promotion in managing variable nullability.

Uploaded by

Loki Legends
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

OBJECT ORIENTED

PROGRAMMING

FLUTTER
• Class is the blueprint of objects and class is the
collection of data members and data function means
which include these fields, getter and setter, and
CLASSES
constructor and functions.
DECLARING CLASS
• Class is the keyword used to initialize the class.
• class_name is the name of the class.
• The body of the class consists of fields, constructors, getter and setter methods, etc.
• Constructor: Initializes the object when an instance is created.
• The body of Constructor includes three things: Class Fields, Class Methods, and Constructors.
• Getters: Retrieves the value of a field.
• Setter: Updates the value of a field with validation.
• Function: Additional methods in the class that perform specific tasks.
• Objects are the instance of the class and they are
declared by using a new keyword followed by the OBJECTS
class name.
• Objects are the instance of the class and they are
declared by using a new keyword followed by the OBJECTS
class name.
OBJECTS
• new is the keyword use to declare the instance of the class
• object_name is the name of the object and its naming is similar to the variable name in dart.
• class_name is the name of the class whose instance variable is been created.
• arguments are the input which are needed to be pass if we are willing to call a constructor.
• In Dart, one class can inherit another class i.e dart
can create a new class from an existing class. We
make use of extend keyword to do so.
INHERITANCE AND
• Polymorphism: Ability of objects to take multiple POLYMORPHISM
forms.
CONCEPT OF INHERITANCE
• Parent Class: It is the class whose properties are inherited by the child class. It is also known as a base class or
superclass.
• Child Class: It is the class that inherits the properties of the other classes. It is also known as a deprived class or
subclass.
• Encapsulation is Restricting access to some
components while exposing others.
ENCAPSULATION AND
• Use _(underscore) to make a variable private.
• Null safety helps avoid null errors by requiring
NULL SAFETY
explicit nullability.
NULL SAFETY
• Null Safety in simple words means a variable cannot contain a ‘null’ value unless you initialized with null to that variable. With
null safety, all the runtime null-dereference errors will now be shown in compile time.
Non-Nullable Types
• When we use null safety, all the types are non-nullable by default. For example, when we declare a variable of type int, the
variable will contain some integer value.
Example:
int marks;
marks = null;
Nullable Types
• To specify if the variable can be null, then you can use the nullable type ? Operator.

The Assertion Operator (!)


• Use the null assertion operator ( ! ) to make Dart treat a nullable expression as non-nullable if you’re certain it isn’t null.
Type Promotion
• Dart’s analyzer, which tells you what compile-time errors and warnings, is intelligent enough to determine whether a nullable
variable is guaranteed to have values that are not null. Dart uses Flow Analysis at runtime for type promotion (flow analysis is a
mechanism that determines the control flow of a program).

Late Keyword
• As we knew that all variables are non-null by default, we can use either the ? operator or the late keyword.
THANK YOU ☺

RYAN FERMO

You might also like