SlideShare a Scribd company logo
1 of 25
Download to read offline
This work is licensed under the Apache 2.0 License
Basics of Flutter
GDSC - SSN College Of
Engineering
This work is licensed under the Apache 2.0 License
What is Mobile Development?
Mobile development involves the development of
software that is intended to run on mobile devices
(smartphones, tablets, etc).
Differentiating factor- mobile development will utilize
unique features and hardware from mobile devices like
touch, Bluetooth, GPS, cameras, and more.
Mobile applications depend upon the device itself.
This work is licensed under the Apache 2.0 License
2 Popular types of Mobile Development
Native app: applications developed to support a specific platform like Android
or iOS. For Android applications, you will use Java or Kotlin. Developers often
prefer native applications because of their ability to fully utilize mobile device
functionality.
Hybrid app: Combines elements from both native apps and web apps. Like
web applications; much of the app is written using technologies like HTML, CSS,
and JavaScript, which is then encapsulated into a native application. Allow
developers to use web technologies.
This work is licensed under the Apache 2.0 License
What is Flutter?
This work is licensed under the Apache 2.0 License
What is Flutter?
Flutter is an open-source Software Development
Kit (SDK) for “building beautiful, natively compiled
applications for mobile, web, and desktop from a
single codebase.”
If a developer has created an amazing application. However, the application is only
supported on iOS. So, the developer decides to spend numerous hours learning
Android to support more users on their application. Even after learning how to build
Android apps, they realize that their application must support all types of Android
screen resolutions. That’s where Flutter comes in.
This work is licensed under the Apache 2.0 License
Flutter essentially consists of two parts:
● Software Development Kit (SDK): A
collection of tools that aid you in
developing your application.
● Framework: A collection of widgets, or UI
elements, that you can add to develop
your application.
This work is licensed under the Apache 2.0 License
● Open-source
● Cross-platform development
● Expansive widget library
● Hot reload
● Thriving Large Developer
Community Support
Features of Flutter
This work is licensed under the Apache 2.0 License
Understanding Widgets
● Basic building blocks of the Flutter UI. Unlike many other frameworks
that separate views, layouts, view controllers, and other elements, Flutter
offers a consistent, unified object model: the widget.
● Widgets are the central class hierarchy in the Flutter framework. A
widget is an immutable description of part of a user interface.
● Like components in React, widgets form a hierarchy and can be nested
within each other. Furthermore, widgets inherit properties from their
parents.
This work is licensed under the Apache 2.0 License
This work is licensed under the Apache 2.0 License
This work is licensed under the Apache 2.0 License
This work is licensed under the Apache 2.0 License
The Dart
Programming
Language
This work is licensed under the Apache 2.0 License
What is Dart?
Dart, a programming language crafted by
Google, is tailored for client-side development,
including web and mobile applications, while
also versatile for creating server-side and
desktop applications.
This work is licensed under the Apache 2.0 License
2
3
1 Optimized for UI
Productive Development
Fast on all platforms
Create using a programming language specifically
designed for UI development needs.
Iteratively refine your app using hot reload to
instantly reflect changes; compiled both
ahead-of-time (AOT) and just-in-time (JIT).
Compile to ARM and x64 machine code for mobile and
desktop platforms, or compile to JavaScript for web
deployment.
Why Dart?
This work is licensed under the Apache 2.0 License
Dart
● Variables
● Conditionals
● Control Flow
● Functions
● Classes
Note: You can use the DartPad online @ https://dartpad.dev/ to play around with Dart. You
can also get the Dart SDK @ https://dart.dev/get-dart
This work is licensed under the Apache 2.0 License
Variables
● Similar to Java/C++/JS
● Very easy to learn
● Dart supports data types
such as int, double, String,
bool, List, Set, Map, etc
● Declared using ‘var’ keyword
● Constants are declared using
‘const’ or ‘final’ keyword
● Comments - //
var name = "Dart"; // String
var year = 2024; // int
const pi = 3.14; // double constant
var planets = ['Mercury', 'Venus', 'Earth', 'Mars']; // List
var path = {
'planet': 'Earth',
'index': 2,
'isHabitable': true
}; // Map
This work is licensed under the Apache 2.0 License
Conditionals
● if statement
● if..else statement
● if..elif..else statement
● switch..case statement
if (num > 0) {
print('$num is positive');
} else if (num < 0) {
print('$num is negative');
} else {
print('$num is neither positive nor negative');
}
switch (fruit) {
case 'apple':
print('Selected fruit is apple');
break;
case 'banana':
print('Selected fruit is banana');
break;
default:
print('Unknown fruit');
}
This work is licensed under the Apache 2.0 License
Control Flow
● Loops
● for loop
● while loop
● do..while loop
for (int i = 0; i < 5; i++) {
print('Count: $i');
}
while (count < 5) {
print('Count: $count');
count++;
}
do {
print('Count: $count');
count++;
} while (count < 5);
This work is licensed under the Apache 2.0 License
Functions
Syntax:
<return_type> <function_name>([<param1>, <param2>,..]){
<body of function>
}
main() - entry point for the execution of dart program. Return type is always void
for main() function.
int add(int a, int b) {
return a + b;
}
void main() {
var result = add(5,10);
print("$result");
}
This work is licensed under the Apache 2.0 License
Classes
Syntax:
class <class_name>{
<body of class>
}
● Constructor of class - no return type, same name as the class.
● Object is created with the help of ‘new’ keyword.
● ‘this’ keyword is used to refer to the current instance of the class.
● Classes can be imported in other dart files using the ‘import’ keyword.
● Dart classes supports many types of inheritance.
● Classes can be extended (inherited) by using ‘extends’ keyword.
● Mainly Dart classes in Flutter extends from Stateless and Stateful classes.
This work is licensed under the Apache 2.0 License
Classes
class Person {
// Properties
String name;
int age;
// Constructor
Person(String name, int age) {
this.name = name;
this.age = age;
}
// Function within the class
void printDetails() {
print('Name: $name, Age: $age');
}
}
void main() {
// Create an object of the Person class
Person person1 = new Person('John',
25);
// Call the function on the object
person1.printDetails();
}
Stateless vs
Stateful Widgets
This work is licensed under the Apache 2.0 License
This work is licensed under the Apache 2.0 License
Stateless and Stateful Widgets
In Flutter, there are 2 kinds of widgets - Stateless and Stateful widgets.
● Stateless widgets are immutable, meaning their properties cannot change once the
widget is built.
● Used in UI components, that do not require mutable state.
● The build() method should be overridden for a stateless widget.
● Stateful widgets are mutable, meaning they can maintain and update their internal
state during their lifetime.
● Used in UI components that need to change dynamically based on user interaction
● The createState() should be overridden for a stateful widget.
● The widget should implement build() and setState() methods.
This work is licensed under the Apache 2.0 License
Stateless Widget
class MyStatelessWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
...
}
}
This work is licensed under the Apache 2.0 License
Stateful Widget
class MyStatefulWidget extends StatefulWidget {
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
void _incrementCounter() {
setState(() {
...
});
}
@override
Widget build(BuildContext context) {
...
}
}

More Related Content

Similar to GDSC-FlutterBasics.pdf

DSC IIITL Flutter Workshop
DSC IIITL Flutter WorkshopDSC IIITL Flutter Workshop
DSC IIITL Flutter WorkshopDSCIIITLucknow
 
Technologies Used in Flutter App Development.pdf
Technologies Used in Flutter App Development.pdfTechnologies Used in Flutter App Development.pdf
Technologies Used in Flutter App Development.pdfNishaadequateinfosof
 
Flutter presentation.pptx
Flutter presentation.pptxFlutter presentation.pptx
Flutter presentation.pptxFalgunSorathiya
 
Introduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fastIntroduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fastBartosz Kosarzycki
 
What is flutter and why should i care?
What is flutter and why should i care?What is flutter and why should i care?
What is flutter and why should i care?Sergi Martínez
 
Dart PPT.pptx
Dart PPT.pptxDart PPT.pptx
Dart PPT.pptxDSCMESCOE
 
Flutter technology Based on Web Development
Flutter technology Based on Web Development Flutter technology Based on Web Development
Flutter technology Based on Web Development divyawani2
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxKotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxtakshilkunadia
 
Chapter 2 Flutter Basics Lecture 1.pptx
Chapter 2 Flutter Basics Lecture 1.pptxChapter 2 Flutter Basics Lecture 1.pptx
Chapter 2 Flutter Basics Lecture 1.pptxfarxaanfarsamo
 
Android App Development - 01 Introduction
Android App Development - 01 IntroductionAndroid App Development - 01 Introduction
Android App Development - 01 IntroductionDiego Grancini
 
Droidcon London 2021 - Full Stack Dart
Droidcon London 2021   - Full Stack DartDroidcon London 2021   - Full Stack Dart
Droidcon London 2021 - Full Stack DartChris Swan
 
Flutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by StepFlutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by StepChandramouli Biyyala
 

Similar to GDSC-FlutterBasics.pdf (20)

DSC IIITL Flutter Workshop
DSC IIITL Flutter WorkshopDSC IIITL Flutter Workshop
DSC IIITL Flutter Workshop
 
Mobile Application Development class 002
Mobile Application Development class 002Mobile Application Development class 002
Mobile Application Development class 002
 
Technologies Used in Flutter App Development.pdf
Technologies Used in Flutter App Development.pdfTechnologies Used in Flutter App Development.pdf
Technologies Used in Flutter App Development.pdf
 
Study Jam Session 2
Study Jam Session 2Study Jam Session 2
Study Jam Session 2
 
Flutter presentation.pptx
Flutter presentation.pptxFlutter presentation.pptx
Flutter presentation.pptx
 
Introduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fastIntroduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fast
 
Flutter101
Flutter101Flutter101
Flutter101
 
What is flutter and why should i care?
What is flutter and why should i care?What is flutter and why should i care?
What is flutter and why should i care?
 
Dart PPT.pptx
Dart PPT.pptxDart PPT.pptx
Dart PPT.pptx
 
PPT Companion to Android
PPT Companion to AndroidPPT Companion to Android
PPT Companion to Android
 
Choose flutter
Choose flutterChoose flutter
Choose flutter
 
Mobile Application Development class 001
Mobile Application Development class 001Mobile Application Development class 001
Mobile Application Development class 001
 
Dart Jump Start
Dart Jump StartDart Jump Start
Dart Jump Start
 
Flutter technology Based on Web Development
Flutter technology Based on Web Development Flutter technology Based on Web Development
Flutter technology Based on Web Development
 
Dart
DartDart
Dart
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxKotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptx
 
Chapter 2 Flutter Basics Lecture 1.pptx
Chapter 2 Flutter Basics Lecture 1.pptxChapter 2 Flutter Basics Lecture 1.pptx
Chapter 2 Flutter Basics Lecture 1.pptx
 
Android App Development - 01 Introduction
Android App Development - 01 IntroductionAndroid App Development - 01 Introduction
Android App Development - 01 Introduction
 
Droidcon London 2021 - Full Stack Dart
Droidcon London 2021   - Full Stack DartDroidcon London 2021   - Full Stack Dart
Droidcon London 2021 - Full Stack Dart
 
Flutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by StepFlutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by Step
 

Recently uploaded

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 

Recently uploaded (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 

GDSC-FlutterBasics.pdf

  • 1. This work is licensed under the Apache 2.0 License Basics of Flutter GDSC - SSN College Of Engineering
  • 2. This work is licensed under the Apache 2.0 License What is Mobile Development? Mobile development involves the development of software that is intended to run on mobile devices (smartphones, tablets, etc). Differentiating factor- mobile development will utilize unique features and hardware from mobile devices like touch, Bluetooth, GPS, cameras, and more. Mobile applications depend upon the device itself.
  • 3. This work is licensed under the Apache 2.0 License 2 Popular types of Mobile Development Native app: applications developed to support a specific platform like Android or iOS. For Android applications, you will use Java or Kotlin. Developers often prefer native applications because of their ability to fully utilize mobile device functionality. Hybrid app: Combines elements from both native apps and web apps. Like web applications; much of the app is written using technologies like HTML, CSS, and JavaScript, which is then encapsulated into a native application. Allow developers to use web technologies.
  • 4. This work is licensed under the Apache 2.0 License What is Flutter?
  • 5. This work is licensed under the Apache 2.0 License What is Flutter? Flutter is an open-source Software Development Kit (SDK) for “building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase.” If a developer has created an amazing application. However, the application is only supported on iOS. So, the developer decides to spend numerous hours learning Android to support more users on their application. Even after learning how to build Android apps, they realize that their application must support all types of Android screen resolutions. That’s where Flutter comes in.
  • 6. This work is licensed under the Apache 2.0 License Flutter essentially consists of two parts: ● Software Development Kit (SDK): A collection of tools that aid you in developing your application. ● Framework: A collection of widgets, or UI elements, that you can add to develop your application.
  • 7. This work is licensed under the Apache 2.0 License ● Open-source ● Cross-platform development ● Expansive widget library ● Hot reload ● Thriving Large Developer Community Support Features of Flutter
  • 8. This work is licensed under the Apache 2.0 License Understanding Widgets ● Basic building blocks of the Flutter UI. Unlike many other frameworks that separate views, layouts, view controllers, and other elements, Flutter offers a consistent, unified object model: the widget. ● Widgets are the central class hierarchy in the Flutter framework. A widget is an immutable description of part of a user interface. ● Like components in React, widgets form a hierarchy and can be nested within each other. Furthermore, widgets inherit properties from their parents.
  • 9. This work is licensed under the Apache 2.0 License
  • 10. This work is licensed under the Apache 2.0 License
  • 11. This work is licensed under the Apache 2.0 License
  • 12. This work is licensed under the Apache 2.0 License The Dart Programming Language
  • 13. This work is licensed under the Apache 2.0 License What is Dart? Dart, a programming language crafted by Google, is tailored for client-side development, including web and mobile applications, while also versatile for creating server-side and desktop applications.
  • 14. This work is licensed under the Apache 2.0 License 2 3 1 Optimized for UI Productive Development Fast on all platforms Create using a programming language specifically designed for UI development needs. Iteratively refine your app using hot reload to instantly reflect changes; compiled both ahead-of-time (AOT) and just-in-time (JIT). Compile to ARM and x64 machine code for mobile and desktop platforms, or compile to JavaScript for web deployment. Why Dart?
  • 15. This work is licensed under the Apache 2.0 License Dart ● Variables ● Conditionals ● Control Flow ● Functions ● Classes Note: You can use the DartPad online @ https://dartpad.dev/ to play around with Dart. You can also get the Dart SDK @ https://dart.dev/get-dart
  • 16. This work is licensed under the Apache 2.0 License Variables ● Similar to Java/C++/JS ● Very easy to learn ● Dart supports data types such as int, double, String, bool, List, Set, Map, etc ● Declared using ‘var’ keyword ● Constants are declared using ‘const’ or ‘final’ keyword ● Comments - // var name = "Dart"; // String var year = 2024; // int const pi = 3.14; // double constant var planets = ['Mercury', 'Venus', 'Earth', 'Mars']; // List var path = { 'planet': 'Earth', 'index': 2, 'isHabitable': true }; // Map
  • 17. This work is licensed under the Apache 2.0 License Conditionals ● if statement ● if..else statement ● if..elif..else statement ● switch..case statement if (num > 0) { print('$num is positive'); } else if (num < 0) { print('$num is negative'); } else { print('$num is neither positive nor negative'); } switch (fruit) { case 'apple': print('Selected fruit is apple'); break; case 'banana': print('Selected fruit is banana'); break; default: print('Unknown fruit'); }
  • 18. This work is licensed under the Apache 2.0 License Control Flow ● Loops ● for loop ● while loop ● do..while loop for (int i = 0; i < 5; i++) { print('Count: $i'); } while (count < 5) { print('Count: $count'); count++; } do { print('Count: $count'); count++; } while (count < 5);
  • 19. This work is licensed under the Apache 2.0 License Functions Syntax: <return_type> <function_name>([<param1>, <param2>,..]){ <body of function> } main() - entry point for the execution of dart program. Return type is always void for main() function. int add(int a, int b) { return a + b; } void main() { var result = add(5,10); print("$result"); }
  • 20. This work is licensed under the Apache 2.0 License Classes Syntax: class <class_name>{ <body of class> } ● Constructor of class - no return type, same name as the class. ● Object is created with the help of ‘new’ keyword. ● ‘this’ keyword is used to refer to the current instance of the class. ● Classes can be imported in other dart files using the ‘import’ keyword. ● Dart classes supports many types of inheritance. ● Classes can be extended (inherited) by using ‘extends’ keyword. ● Mainly Dart classes in Flutter extends from Stateless and Stateful classes.
  • 21. This work is licensed under the Apache 2.0 License Classes class Person { // Properties String name; int age; // Constructor Person(String name, int age) { this.name = name; this.age = age; } // Function within the class void printDetails() { print('Name: $name, Age: $age'); } } void main() { // Create an object of the Person class Person person1 = new Person('John', 25); // Call the function on the object person1.printDetails(); }
  • 22. Stateless vs Stateful Widgets This work is licensed under the Apache 2.0 License
  • 23. This work is licensed under the Apache 2.0 License Stateless and Stateful Widgets In Flutter, there are 2 kinds of widgets - Stateless and Stateful widgets. ● Stateless widgets are immutable, meaning their properties cannot change once the widget is built. ● Used in UI components, that do not require mutable state. ● The build() method should be overridden for a stateless widget. ● Stateful widgets are mutable, meaning they can maintain and update their internal state during their lifetime. ● Used in UI components that need to change dynamically based on user interaction ● The createState() should be overridden for a stateful widget. ● The widget should implement build() and setState() methods.
  • 24. This work is licensed under the Apache 2.0 License Stateless Widget class MyStatelessWidget extends StatelessWidget { @override Widget build(BuildContext context) { ... } }
  • 25. This work is licensed under the Apache 2.0 License Stateful Widget class MyStatefulWidget extends StatefulWidget { @override _MyStatefulWidgetState createState() => _MyStatefulWidgetState(); } class _MyStatefulWidgetState extends State<MyStatefulWidget> { void _incrementCounter() { setState(() { ... }); } @override Widget build(BuildContext context) { ... } }