SlideShare une entreprise Scribd logo
1  sur  62
Télécharger pour lire hors ligne
Inside Flutter:
Widgets, Elements, and RenderObjects
Hansol Lee
TOC 💁‍♂
- Introduction
- Flutter’s layers
- dart:ui
- RenderObjects
- Widgets
- Widgets, Elements, and RenderObjects
- Summary
Introduction
- Hansol Lee
- Working at Kakao Corp. as Android Developer
- Projects related with Flutter
- https://github.com/giantsol/Blue-Diary
- https://github.com/giantsol/Yellow-Box
- Mentoring “Contributing to Flutter”:
https://github.com/flutter-moum/flutter-moum
- GitHub: https://github.com/giantsol
Introduction
Widget, Element, RenderObject
What are they?
How do they work?
Flutter’s Layers
dart:ui
RenderObjects
Widgets
Flutter’s Layers
dart:ui
RenderObjects
Widgets
RenderObjects built on top of dart:ui
Widgets built on top of RenderObjects
Elements between Widgets and RenderObjects
doing some secret stuff 🕵
Flutter’s Layers
dart:ui
RenderObjects
Widgets
RenderObjects built on top of dart:ui
Widgets built on top of RenderObjects
Elements between Widgets and RenderObjects
doing some secret stuff 🕵
Flutter’s Layers
RenderObjects
Widgets
RenderObjects built on top of dart:ui
Widgets built on top of RenderObjects
dart:ui
dart:ui
Contains basic tools to draw on screen.
e.g. Canvas, Paint, Rect …
dart:ui
Contains basic tools to draw on screen.
e.g. Canvas, Paint, Rect …
You can create a Flutter app using dart:ui directly!
dart:ui
dart:ui
Register a callback to be called on every
draw frame.
Draw using Canvas API. 🎨
Let the window render what has been
drawn to the canvas!
The most primitive way to use Flutter.
dart:ui
The most primitive way to use Flutter.
Need to do complicate calculations on your own.
Certainly not extensible! 🤦‍♂
dart:ui
The most primitive way to use Flutter.
Need to do complicate calculations on your own.
Certainly not extensible! 🤦‍♂
dart:ui
dart:ui
Widgets
RenderObjects
RenderObjects
RenderObject: an individual object that implements methods to draw itself on
screen (e.g. size, layout, paint …)
e.g. RenderImage, RenderPadding, RenderDecoratedBox …
RenderObjects
RenderObject: an individual object that implements methods to draw itself on
screen (e.g. size, layout, paint …)
e.g. RenderImage, RenderPadding, RenderDecoratedBox …
Similarly, you can create a Flutter app using RenderObjects directly!
RenderObjects
RenderObjects
If you want to dynamically change some value, you need to
keep the reference of the target RenderObject.
Update RenderObject’s text property manually to reflect the
change in the next frame.
RenderObjects
Advantages:
- Much more convenient to use (almost like Widgets! 🤷‍♂)
- Parent-child relation allows for optimizations (e.g. when to redraw or not?)
RenderObjects
Disadvantages:
- Since RenderObjects are mutable, we need to manage their states directly.
- This makes code unflexible and vulnerable to get “dirty”. ⚠
RenderObjects
Disadvantages:
- Since RenderObjects are mutable, we need to manage their states directly.
- This makes code unflexible and vulnerable to get “dirty”. ⚠
dart:ui
RenderObjects
Widgets
Widgets
DecoratedBox(
child: Center(
child: Text(title)
)
)
Say we have a simple Widget tree like so..
Widgets
DecoratedBox(
child: Center(
child: Text(title)
)
)
title = newTitle We want newTitle to be reflected automatically just by updating the
variable (without referencing and mutating the object ourselves).
Widgets
DecoratedBox(
child: Center(
child: Icon(title)
)
)
title = newTitle
Also, we want to swap objects flexibly without bothering any
possible outside references.
Widgets
DecoratedBox(
child: Center(
child: Icon(title)
)
)
title = newTitle
Immutability makes this possible. 🎉
Widget: an immutable configuration data defining how to create a
corresponding RenderObject.
e.g. Image, Padding, DecoratedBox …
Widgets
Widget: an immutable configuration data defining how to create a
corresponding RenderObject.
e.g. Image, Padding, DecoratedBox …
The most typical way to create a Flutter app.
Widgets
Widgets
Widgets
How does this Widget tree gets drawn on screen?
Flutter has three trees: Widget tree, Element tree, and RenderObject tree.
Widgets, Elements, and RenderObjects
Flutter has three trees: Widget tree, Element tree, and RenderObject tree.
Widgets are immutable, so they are always recreated; they only hold
lightweight configuration data.
Widgets, Elements, and RenderObjects
Flutter has three trees: Widget tree, Element tree, and RenderObject tree.
Widgets are immutable, so they are always recreated; they only hold
lightweight configuration data.
RenderObjects are mutable, so they are recreated only when necessary; they
hold heavyweight data and calculations needed to draw on screen.
Widgets, Elements, and RenderObjects
Flutter has three trees: Widget tree, Element tree, and RenderObject tree.
Widgets are immutable, so they are always recreated; they only hold
lightweight configuration data.
RenderObjects are mutable, so they are recreated only when necessary; they
hold heavyweight data and calculations needed to draw on screen.
When we put a Widget tree into runApp() function, it transforms a Widget tree
into a RenderObject tree.
Widgets, Elements, and RenderObjects
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Text
RenderObject Tree
RenderDecoratedBox
RenderPositionedBox
RenderParagraph
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Text
RenderObject Tree
RenderDecoratedBox
RenderPositionedBox
RenderParagraph
How? 🤷‍♂
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Text
RenderObject Tree
RenderDecoratedBox
RenderPositionedBox
RenderParagraph
Element Tree
Element
Element
Element
Elements manage how to transform always-recreated Widgets into
rarely-recreated RenderObjects efficiently.
Widgets, Elements, and RenderObjects
Elements manage how to transform always-recreated Widgets into
rarely-recreated RenderObjects efficiently.
Elements play a key role in achieving both flexible UI programming with
immutable Widgets and fast runtime performance by reusing underlying
RenderObjects.
Widgets, Elements, and RenderObjects
Elements manage how to transform always-recreated Widgets into
rarely-recreated RenderObjects efficiently.
Elements play a key role in achieving both flexible UI programming with
immutable Widgets and fast runtime performance by reusing underlying
RenderObjects.
Let’s see how it works! 👨‍🏫
Widgets, Elements, and RenderObjects
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Text
“Hello”
RenderObject TreeElement Tree
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Text
“Hello”
RenderObject TreeElement Tree
Element
createElement()
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Text
“Hello”
RenderObject TreeElement Tree
Element
createRenderObject()
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Text
“Hello”
RenderObject TreeElement Tree
Element RenderDecoratedBox
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Text
“Hello”
RenderObject TreeElement Tree
Element RenderDecoratedBox
Element
createElement()
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Text
“Hello”
RenderObject TreeElement Tree
Element RenderDecoratedBox
Element
createRenderObject()
RenderPositionedBox
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Text
“Hello”
RenderObject TreeElement Tree
Element RenderDecoratedBox
Element RenderPositionedBox
RenderParagraph
“Hello”
Element
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Image
RenderObject TreeElement Tree
Element RenderDecoratedBox
Element RenderPositionedBox
RenderParagraph
“Hello”
Element
Widgets rebuilt!
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Image
RenderObject TreeElement Tree
Element RenderDecoratedBox
Element RenderPositionedBox
RenderParagraph
“Hello”
Element
canUpdate()
Compares runtimeType and key
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Image
RenderObject TreeElement Tree
Element RenderDecoratedBox
Element RenderPositionedBox
RenderParagraph
“Hello”
Element
updateRenderObject()
RenderDecoratedBox
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Image
RenderObject TreeElement Tree
Element
Element RenderPositionedBox
RenderParagraph
“Hello”
Element
RenderDecoratedBox
canUpdate()
updateRenderObject()
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Image
RenderObject TreeElement Tree
Element
Element RenderPositionedBox
RenderParagraph
“Hello”
Element
RenderDecoratedBox
canUpdate()
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Image
RenderObject TreeElement Tree
Element
Element RenderPositionedBox
RenderDecoratedBox
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Image
RenderObject TreeElement Tree
Element
Element RenderPositionedBox
RenderDecoratedBox
Element
createElement()
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Image
RenderObject TreeElement Tree
Element
Element RenderPositionedBox
RenderDecoratedBox
Element
createRenderObject()
RenderImage
Widgets, Elements, and RenderObjects
Widget Tree
DecoratedBox
Center
Image
RenderObject TreeElement Tree
Element
Element RenderPositionedBox
RenderDecoratedBox
Element RenderImage
Only these are recreated!
- RenderObjects are built on top of dart:ui, and Widgets are built on top of
RenderObjects.
Summary
dart:ui
RenderObjects
Widgets
- RenderObjects are built on top of dart:ui, and Widgets are built on top of
RenderObjects.
- Widgets allow for flexible and declarative way of programming.
Summary
- RenderObjects are built on top of dart:ui, and Widgets are built on top of
RenderObjects.
- Widgets allow for flexible and declarative way of programming.
- Widgets, Elements, and RenderObjects work together to achieve both
flexible programming and fast runtime performance.
Summary
- RenderObjects are built on top of dart:ui, and Widgets are built on top of
RenderObjects.
- Widgets allow for flexible and declarative way of programming.
- Widgets, Elements, and RenderObjects work together to achieve both
flexible programming and fast runtime performance.
- Widgets configure, Elements manage, RenderObjects paint.
Summary
Summary
Reference:
https://www.youtube.com/watch?v=dkyY9WCGMi0&t=163s
https://flutter.dev/docs/resources/inside-flutter
https://www.youtube.com/watch?v=UUfXWzp0-DU&t=2s
https://www.youtube.com/watch?v=996ZgFRENMs
https://nevercode.io/blog/flutter-vs-react-native-a-developers-perspective/
https://github.com/flutter/flutter/wiki/The-Engine-architecture
https://hackernoon.com/understanding-react-native-bridge-concept-e9526066ddb8
https://medium.com/icnh/flutter-without-flutter-15177c91d066
https://stackoverflow.com/a/53234826
Thank you

Contenu connexe

Tendances

Tendances (20)

Flutter
FlutterFlutter
Flutter
 
Flutter Bootcamp
Flutter BootcampFlutter Bootcamp
Flutter Bootcamp
 
Google flutter and why does it matter
Google flutter and why does it matterGoogle flutter and why does it matter
Google flutter and why does it matter
 
Flutter introduction
Flutter introductionFlutter introduction
Flutter introduction
 
Flutter beyond hello world
Flutter beyond hello worldFlutter beyond hello world
Flutter beyond hello world
 
Google flutter the easy and practical way
Google flutter the easy and practical wayGoogle flutter the easy and practical way
Google flutter the easy and practical way
 
Developer Student Clubs NUK - Flutter for Beginners
Developer Student Clubs NUK - Flutter for BeginnersDeveloper Student Clubs NUK - Flutter for Beginners
Developer Student Clubs NUK - Flutter for Beginners
 
What and Why Flutter? What is a Widget in Flutter?
What and Why Flutter? What is a Widget in Flutter?What and Why Flutter? What is a Widget in Flutter?
What and Why Flutter? What is a Widget in Flutter?
 
Flutter presentation.pptx
Flutter presentation.pptxFlutter presentation.pptx
Flutter presentation.pptx
 
Developing Cross platform apps in flutter (Android, iOS, Web)
Developing Cross platform apps in flutter (Android, iOS, Web)Developing Cross platform apps in flutter (Android, iOS, Web)
Developing Cross platform apps in flutter (Android, iOS, Web)
 
Flutter session 01
Flutter session 01Flutter session 01
Flutter session 01
 
Hello Flutter
Hello FlutterHello Flutter
Hello Flutter
 
A flight with Flutter
A flight with FlutterA flight with Flutter
A flight with Flutter
 
Flutter Tutorial For Beginners | Edureka
Flutter Tutorial For Beginners | EdurekaFlutter Tutorial For Beginners | Edureka
Flutter Tutorial For Beginners | Edureka
 
Dart and Flutter Basics.pptx
Dart and Flutter Basics.pptxDart and Flutter Basics.pptx
Dart and Flutter Basics.pptx
 
Flutter workshop
Flutter workshopFlutter workshop
Flutter workshop
 
Introduction to Flutter
Introduction to FlutterIntroduction to Flutter
Introduction to Flutter
 
Introduction to flutter
Introduction to flutter Introduction to flutter
Introduction to flutter
 
The magic of flutter
The magic of flutterThe magic of flutter
The magic of flutter
 
Flutter introduction
Flutter introductionFlutter introduction
Flutter introduction
 

Similaire à Inside Flutter: Widgets, Elements, and RenderObjects

Android | Busy Java Developers Guide to Android: UI | Ted Neward
Android | Busy Java Developers Guide to Android: UI | Ted NewardAndroid | Busy Java Developers Guide to Android: UI | Ted Neward
Android | Busy Java Developers Guide to Android: UI | Ted Neward
JAX London
 
How to create ui using droid draw
How to create ui using droid drawHow to create ui using droid draw
How to create ui using droid draw
info_zybotech
 
Introduction To Dojo
Introduction To DojoIntroduction To Dojo
Introduction To Dojo
yoavrubin
 
FlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.pptFlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.ppt
KevinNemo
 
Android ui layout
Android ui layoutAndroid ui layout
Android ui layout
Krazy Koder
 

Similaire à Inside Flutter: Widgets, Elements, and RenderObjects (20)

Flutter beyond Hello world talk
Flutter beyond Hello world talkFlutter beyond Hello world talk
Flutter beyond Hello world talk
 
Android | Busy Java Developers Guide to Android: UI | Ted Neward
Android | Busy Java Developers Guide to Android: UI | Ted NewardAndroid | Busy Java Developers Guide to Android: UI | Ted Neward
Android | Busy Java Developers Guide to Android: UI | Ted Neward
 
Flutter beyond hello world
Flutter beyond hello worldFlutter beyond hello world
Flutter beyond hello world
 
How to create ui using droid draw
How to create ui using droid drawHow to create ui using droid draw
How to create ui using droid draw
 
Flutter beyond hello world GCDC Egypt Devfest 2019
Flutter beyond hello world GCDC Egypt  Devfest 2019Flutter beyond hello world GCDC Egypt  Devfest 2019
Flutter beyond hello world GCDC Egypt Devfest 2019
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core Concepts
 
Build UI of the Future with React 360
Build UI of the Future with React 360Build UI of the Future with React 360
Build UI of the Future with React 360
 
Android Ui
Android UiAndroid Ui
Android Ui
 
Android UI
Android UI Android UI
Android UI
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 
What Is BuildContext In Flutter And It's Importance
What Is BuildContext In Flutter And It's ImportanceWhat Is BuildContext In Flutter And It's Importance
What Is BuildContext In Flutter And It's Importance
 
Flutter vs ReactNative
Flutter vs ReactNativeFlutter vs ReactNative
Flutter vs ReactNative
 
Introduction To Dojo
Introduction To DojoIntroduction To Dojo
Introduction To Dojo
 
FlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.pptFlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.ppt
 
The battle between the states (all about flutter stateless & stateful widgets...
The battle between the states (all about flutter stateless & stateful widgets...The battle between the states (all about flutter stateless & stateful widgets...
The battle between the states (all about flutter stateless & stateful widgets...
 
React Native Workshop - React Alicante
React Native Workshop - React AlicanteReact Native Workshop - React Alicante
React Native Workshop - React Alicante
 
The virtual DOM and how react uses it internally
The virtual DOM and how react uses it internallyThe virtual DOM and how react uses it internally
The virtual DOM and how react uses it internally
 
Android ui layout
Android ui layoutAndroid ui layout
Android ui layout
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
Google Associate Android Developer Certification
Google Associate Android Developer CertificationGoogle Associate Android Developer Certification
Google Associate Android Developer Certification
 

Dernier

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Inside Flutter: Widgets, Elements, and RenderObjects