SlideShare a Scribd company logo
Ahmed Abu Eldahab
GDE Flutter & Dart
@dahabdev
Null Safety in Dart and Flutter ,
The whole Story!
Ahmed Abu Eldahab
Google Developer Expert in Flutter & Dart
Senior Technical Consultant
Kortobaa LLC CTO
/Dahabdev
bit.ly/dahab-youtube
/DahabDev
1960
Tony Hoare
Sir Charles Antony Richard Hoare born 11 January 1934)
- is a British computer scientist. He developed the sorting algorithm
quicksort in 1959–1960.[5] He also developed Hoare logic for
verifying program correctness.
https://en.wikipedia.org/wiki/Tony_Hoare /DahabDev
- In 1960, Hoare left the Soviet Union and began working at Elliott Brothers.
- After 9 months of programming he was asked to design a new
programming language !!
- Most software was still written in machine code.
- In the library was a 23-page booklet entitled "Report on the international
language ALGOL60"
- He used it as a basis for the new language.
- In order to implement error messages, an array had a check to verify
whether its reference was in the bounds!.
- Adding checks to arrays added space and time to the program !.
- Then he went and invented the null pointer. Or he either have to
check every reference.
https://en.wikipedia.org/wiki/Tony_Hoare
Tony Hoare in Moscow 1960
/DahabDev
Variables
String name = ‘Ahmed’;
Type Name Value
/DahabDev
Memory Allocation
String name = ‘Ahmed’;
NameType Init val
Address Value
0012CCGWH80 Ahmed
Identifier
Memory
name
/DahabDev
Variables
String name;
NameType
/DahabDev
Memory Allocation
Identifier
Memory
name
String name;
NameType
?
Nowhere
Null
Pointer
/DahabDev
Null
Pointer/Reference
- A null pointer is a pointer that does
not point to any memory location.
- It represents an invalid memory
location .
- when a null value is assigned to a
pointer then the pointer is considered
as null pointer.
/DahabDev
Null Pointer/Reference Exception (NPE)
- Invoking a method from a null object.
- Accessing or modifying a null object’s field.
- Taking the length of null, as if it were an array.
- Accessing or modifying the slots of null
object, as if it were an array.
/DahabDev
Something was called on null
Something was called on null
/DahabDev
Null Pointer Exception (NPE)
/DahabDev
Tony Hoare
https://en.wikipedia.org/wiki/Tony_Hoare
I call it my billion-dollar mistake. It was the invention of the null
reference in 1965. ... This has led to innumerable errors,
vulnerabilities, and system crashes, which have probably caused
a billion dollars of pain and damage in the last forty years.
2009
/DahabDev
Tony Hoare
https://en.wikipedia.org/wiki/Tony_Hoare
- Null references have historically been a bad idea.
- Programming language designers should be responsible for the
errors in programs written in that language.
- If the billion dollar mistake was the null pointer, the C gets()
function is a multi-billion dollar mistake that created the
opportunity for malware and viruses to thrive (Buffer overflow)
/DahabDev
Important Expressions
Dynamic Type system Static Type system Null Safety
Unsound Null SafetySound Null Safety
/DahabDev
Dart null safety
https://www.youtube.com/watch?v=iYhOU9AuaFs
https://medium.com/dartlang/announcing-dart-nu
ll-safety-beta-87610fee6730
/DahabDev
Dart Null Safety
Null safety is the largest
change we’ve made to Dart
since we replaced the original
unsound optional type system
with a sound static type
system in Dart 2.0.
/DahabDev
https://dartpad.dev
/DahabDev
https://dartpad.dev /DahabDev
Dart
https://dartpad.dev /DahabDev
Dart
https://dartpad.dev /DahabDev
Dart
Dart Null Safety
https://nullsafety.dartpad.dev /DahabDev
Dart Null safety principles
/DahabDev
Dart null safety support is based on the following three core design principles:
● Non-nullable by default. Unless you explicitly tell Dart that a variable can be null, it’s considered non-nullable.
This default was chosen after research found that non-null was by far the most common choice in APIs.
● Incrementally adoptable. You choose what to migrate to null safety, and when. You can migrate incrementally,
mixing null-safe and non-null-safe code in the same project. We provide tools to help you with the migration.
● Fully sound. Dart’s null safety is sound, which enables compiler optimizations. If the type system determines
that something isn’t null, then that thing can never be null. Once you migrate your whole project and its
dependencies to null safety, you reap the full benefits of soundness —- not only fewer bugs, but smaller
binaries and faster execution
https://dart.dev/null-safety
/DahabDev
- All variables are non-nullable by default
- If the variable can have the value null, add ? to its type declaration.
String? name = null;
- If you know that a non-nullable variable will be initialized to a non-null value
before it’s used, but the Dart analyzer doesn’t agree, insert late before the
variable’s type.
late String name;
Dart null safety roles
https://dart.dev/null-safety
/DahabDev
- When using a nullable variable or expression, be sure to handle null values. For
example, you can use an if statement, the ?? operator, or the ?. operator to
handle possible null values.
String value = name ?? ''; // '' if it's null; otherwise, the String
- If you’re sure that an expression with a nullable type isn’t null, you can add ! to
make Dart treat it as non-nullable:
String? name = 'Ahmed';
String value = name!; // `name!` is an String.
// This throws if name is null.
Dart null safety roles
https://dart.dev/null-safety
Dart null safety roles
/DahabDev
- Once you opt into null safety, you can’t use the member access operator (.) if the
operand might be null. Instead, you can use the null-aware version of that
operator (?.):
double? d;
print(d?.floor()); // Uses `?.` instead of `.` to invoke `floor()`.
- If you’re sure that an expression with a nullable type isn’t null, you can add ! to
make Dart treat it as non-nullable:
String? name = 'Ahmed';
String value = name!; // `name!` is an String.
// This throws if name is null.
https://dart.dev/null-safety
list, set, and map
/DahabDev
https://dart.dev/null-safety
list, set, and map
/DahabDev
https://dart.dev/null-safety
/DahabDev
Migrating to null safety steps
https://dart.dev/null-safety/migration-guide
/DahabDev
Migrating to null safety steps
https://dart.dev/null-safety/migration-guide
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
Everything is ok?
HIT APPLY MIGRATION BUTTON !
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
The analyzer can be wrong sometimes !
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
/DahabDev
How to practice Null safety?
https://nullsafety.dartpad.dev
/DahabDev
Migrating to null safety
Migrating to null safety
/DahabDev
1. Wait for the packages that you depend on to migrate.
2. Migrate your package’s code, preferably using the interactive migration tool.
3. Statically analyze your package’s code.
4. Test to make sure your changes work.
5. If the package is already on pub.dev, publish the null-safe version as a
prerelease version.
https://dart.dev/null-safety
Thanks
bit.ly/dahab-youtube
Ahmed Abu Eldahab
Google Developer Expert in Flutter & Dart
Senior Technical Consultant
Kortobaa LLC CTO
/Dahabdev

More Related Content

What's hot

Golang 101
Golang 101Golang 101
Golang 101
宇 傅
 
Dart workshop
Dart workshopDart workshop
Dart workshop
Vishnu Suresh
 
Dart Programming.pptx
Dart Programming.pptxDart Programming.pptx
Dart Programming.pptx
AnanthalakshmiN4
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
Doug Jones
 
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
Bartosz Kosarzycki
 
Javascript
JavascriptJavascript
Javascript
mussawir20
 
flutter.school #HelloWorld
flutter.school #HelloWorldflutter.school #HelloWorld
flutter.school #HelloWorld
Frederik Schweiger
 
Go language presentation
Go language presentationGo language presentation
Go language presentation
paramisoft
 
Overview of PHP and MYSQL
Overview of PHP and MYSQLOverview of PHP and MYSQL
Overview of PHP and MYSQL
Deblina Chowdhury
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
Nidhi mishra
 
Android styles and themes
Android   styles and themesAndroid   styles and themes
Android styles and themesDeepa Rani
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
SudhanshuVijay3
 
WEB TECHNOLOGIES- PHP Programming
WEB TECHNOLOGIES-  PHP ProgrammingWEB TECHNOLOGIES-  PHP Programming
Introduction to go language programming
Introduction to go language programmingIntroduction to go language programming
Introduction to go language programming
Mahmoud Masih Tehrani
 
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)
Priyanka Tyagi
 
Javascript
JavascriptJavascript
Javascript
Nagarajan
 
1 Introduction To Java Technology
1 Introduction To Java Technology 1 Introduction To Java Technology
1 Introduction To Java Technology
dM Technologies
 

What's hot (20)

Golang 101
Golang 101Golang 101
Golang 101
 
Dart workshop
Dart workshopDart workshop
Dart workshop
 
Dart Programming.pptx
Dart Programming.pptxDart Programming.pptx
Dart Programming.pptx
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
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
 
Javascript
JavascriptJavascript
Javascript
 
flutter.school #HelloWorld
flutter.school #HelloWorldflutter.school #HelloWorld
flutter.school #HelloWorld
 
Go language presentation
Go language presentationGo language presentation
Go language presentation
 
Overview of PHP and MYSQL
Overview of PHP and MYSQLOverview of PHP and MYSQL
Overview of PHP and MYSQL
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
PHP slides
PHP slidesPHP slides
PHP slides
 
Android styles and themes
Android   styles and themesAndroid   styles and themes
Android styles and themes
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
WEB TECHNOLOGIES- PHP Programming
WEB TECHNOLOGIES-  PHP ProgrammingWEB TECHNOLOGIES-  PHP Programming
WEB TECHNOLOGIES- PHP Programming
 
Introduction to go language programming
Introduction to go language programmingIntroduction to go language programming
Introduction to go language programming
 
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)
 
Javascript
JavascriptJavascript
Javascript
 
1 Introduction To Java Technology
1 Introduction To Java Technology 1 Introduction To Java Technology
1 Introduction To Java Technology
 

Similar to Null safety in dart and flutter , the whole story!

Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to Android
Vlatko Kosturjak
 
Hacking - high school intro
Hacking - high school introHacking - high school intro
Hacking - high school intro
Peter Hlavaty
 
hover.in at CUFP 2009
hover.in at CUFP 2009hover.in at CUFP 2009
hover.in at CUFP 2009
Bhasker Kode
 
Open event (show&tell april 2016)
Open event (show&tell april 2016)Open event (show&tell april 2016)
Open event (show&tell april 2016)
Jorge López-Lago
 
Why Rust? by Edd Barrett (codeHarbour December 2019)
Why Rust? by Edd Barrett (codeHarbour December 2019)Why Rust? by Edd Barrett (codeHarbour December 2019)
Why Rust? by Edd Barrett (codeHarbour December 2019)
Alex Cachia
 
ITI MDW 2018 Event Talk "building beautiful apps using google flutter"
ITI MDW 2018 Event Talk "building beautiful apps using google flutter"ITI MDW 2018 Event Talk "building beautiful apps using google flutter"
ITI MDW 2018 Event Talk "building beautiful apps using google flutter"
Ahmed Abu Eldahab
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
gslicraf
 
Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...
Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...
Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...
Codemotion
 
Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!
Aaron Zauner
 
UnDeveloper Studio
UnDeveloper StudioUnDeveloper Studio
UnDeveloper Studio
Christien Rioux
 
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
雅太 西田
 
Fluid, Fluent APIs
Fluid, Fluent APIsFluid, Fluent APIs
Fluid, Fluent APIs
Erik Rose
 
Bigdata Presentation
Bigdata PresentationBigdata Presentation
Bigdata Presentation
Yonas Gidey
 
Bigdata presentation
Bigdata presentationBigdata presentation
Bigdata presentation
Yonas Gidey
 
Simplest-Ownage-Human-Observed… - Routers
 Simplest-Ownage-Human-Observed… - Routers Simplest-Ownage-Human-Observed… - Routers
Simplest-Ownage-Human-Observed… - RoutersLogicaltrust pl
 
Filip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersFilip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersYury Chemerkin
 
LibreSSL, one year later
LibreSSL, one year laterLibreSSL, one year later
LibreSSL, one year later
Giovanni Bechis
 
Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic RevisitedAdam Keys
 
Php training100%placement-in-mumbai
Php training100%placement-in-mumbaiPhp training100%placement-in-mumbai
Php training100%placement-in-mumbai
vibrantuser
 

Similar to Null safety in dart and flutter , the whole story! (20)

Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to Android
 
Hacking - high school intro
Hacking - high school introHacking - high school intro
Hacking - high school intro
 
hover.in at CUFP 2009
hover.in at CUFP 2009hover.in at CUFP 2009
hover.in at CUFP 2009
 
Open event (show&tell april 2016)
Open event (show&tell april 2016)Open event (show&tell april 2016)
Open event (show&tell april 2016)
 
Why Rust? by Edd Barrett (codeHarbour December 2019)
Why Rust? by Edd Barrett (codeHarbour December 2019)Why Rust? by Edd Barrett (codeHarbour December 2019)
Why Rust? by Edd Barrett (codeHarbour December 2019)
 
ITI MDW 2018 Event Talk "building beautiful apps using google flutter"
ITI MDW 2018 Event Talk "building beautiful apps using google flutter"ITI MDW 2018 Event Talk "building beautiful apps using google flutter"
ITI MDW 2018 Event Talk "building beautiful apps using google flutter"
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...
Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...
Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...
 
Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!
 
UnDeveloper Studio
UnDeveloper StudioUnDeveloper Studio
UnDeveloper Studio
 
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
 
Fluid, Fluent APIs
Fluid, Fluent APIsFluid, Fluent APIs
Fluid, Fluent APIs
 
Bigdata Presentation
Bigdata PresentationBigdata Presentation
Bigdata Presentation
 
Bigdata presentation
Bigdata presentationBigdata presentation
Bigdata presentation
 
Simplest-Ownage-Human-Observed… - Routers
 Simplest-Ownage-Human-Observed… - Routers Simplest-Ownage-Human-Observed… - Routers
Simplest-Ownage-Human-Observed… - Routers
 
Filip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersFilip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routers
 
LibreSSL, one year later
LibreSSL, one year laterLibreSSL, one year later
LibreSSL, one year later
 
Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic Revisited
 
Opensource
OpensourceOpensource
Opensource
 
Php training100%placement-in-mumbai
Php training100%placement-in-mumbaiPhp training100%placement-in-mumbai
Php training100%placement-in-mumbai
 

More from Ahmed Abu Eldahab

The Flutter Job Market At The Moment
The Flutter Job Market At The MomentThe Flutter Job Market At The Moment
The Flutter Job Market At The Moment
Ahmed Abu Eldahab
 
Flutter A year of creativity!
Flutter A year of creativity!Flutter A year of creativity!
Flutter A year of creativity!
Ahmed Abu Eldahab
 
Flutter latest updates and features 2022
Flutter latest updates and features 2022Flutter latest updates and features 2022
Flutter latest updates and features 2022
Ahmed Abu Eldahab
 
Flutter 2.8 features and updates
Flutter 2.8 features and updatesFlutter 2.8 features and updates
Flutter 2.8 features and updates
Ahmed Abu Eldahab
 
6 x1 flutter_talk
6 x1 flutter_talk6 x1 flutter_talk
6 x1 flutter_talk
Ahmed Abu Eldahab
 
What's new in flutter and dart in 2020
 What's new in flutter and dart in 2020   What's new in flutter and dart in 2020
What's new in flutter and dart in 2020
Ahmed Abu Eldahab
 
Build responsive applications with google flutter
Build responsive applications with  google flutterBuild responsive applications with  google flutter
Build responsive applications with google flutter
Ahmed Abu Eldahab
 
Becoming a software developer
Becoming a software developerBecoming a software developer
Becoming a software developer
Ahmed Abu Eldahab
 
Build web applications using google flutter part 2
Build web applications using google flutter part 2Build web applications using google flutter part 2
Build web applications using google flutter part 2
Ahmed Abu Eldahab
 
Build web applications using google flutter
Build web applications using google flutterBuild web applications using google flutter
Build web applications using google flutter
Ahmed Abu Eldahab
 
Google flutter the easy and practical way IEEE Alazhar
Google flutter the easy and practical way IEEE AlazharGoogle flutter the easy and practical way IEEE Alazhar
Google flutter the easy and practical way IEEE Alazhar
Ahmed Abu Eldahab
 
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
Ahmed Abu Eldahab
 
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
Ahmed Abu Eldahab
 
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
Ahmed Abu Eldahab
 
Cybersecurity in an IoT and Mobile World
Cybersecurity in an IoT and Mobile WorldCybersecurity in an IoT and Mobile World
Cybersecurity in an IoT and Mobile World
Ahmed Abu Eldahab
 
Flutter state management from zero to hero
Flutter state management from zero to heroFlutter state management from zero to hero
Flutter state management from zero to hero
Ahmed Abu Eldahab
 
Flutter state management from zero to hero
Flutter state management from zero to heroFlutter state management from zero to hero
Flutter state management from zero to hero
Ahmed Abu Eldahab
 
Building your actions for Google Assistant
Building your actions for Google AssistantBuilding your actions for Google Assistant
Building your actions for Google Assistant
Ahmed Abu Eldahab
 
Building beautiful apps with Google flutter
Building beautiful apps with Google flutterBuilding beautiful apps with Google flutter
Building beautiful apps with Google flutter
Ahmed Abu Eldahab
 
Building Successful Apps with Google Firebase
Building Successful Apps with Google FirebaseBuilding Successful Apps with Google Firebase
Building Successful Apps with Google Firebase
Ahmed Abu Eldahab
 

More from Ahmed Abu Eldahab (20)

The Flutter Job Market At The Moment
The Flutter Job Market At The MomentThe Flutter Job Market At The Moment
The Flutter Job Market At The Moment
 
Flutter A year of creativity!
Flutter A year of creativity!Flutter A year of creativity!
Flutter A year of creativity!
 
Flutter latest updates and features 2022
Flutter latest updates and features 2022Flutter latest updates and features 2022
Flutter latest updates and features 2022
 
Flutter 2.8 features and updates
Flutter 2.8 features and updatesFlutter 2.8 features and updates
Flutter 2.8 features and updates
 
6 x1 flutter_talk
6 x1 flutter_talk6 x1 flutter_talk
6 x1 flutter_talk
 
What's new in flutter and dart in 2020
 What's new in flutter and dart in 2020   What's new in flutter and dart in 2020
What's new in flutter and dart in 2020
 
Build responsive applications with google flutter
Build responsive applications with  google flutterBuild responsive applications with  google flutter
Build responsive applications with google flutter
 
Becoming a software developer
Becoming a software developerBecoming a software developer
Becoming a software developer
 
Build web applications using google flutter part 2
Build web applications using google flutter part 2Build web applications using google flutter part 2
Build web applications using google flutter part 2
 
Build web applications using google flutter
Build web applications using google flutterBuild web applications using google flutter
Build web applications using google flutter
 
Google flutter the easy and practical way IEEE Alazhar
Google flutter the easy and practical way IEEE AlazharGoogle flutter the easy and practical way IEEE Alazhar
Google flutter the easy and practical way IEEE Alazhar
 
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
 
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
 
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
 
Cybersecurity in an IoT and Mobile World
Cybersecurity in an IoT and Mobile WorldCybersecurity in an IoT and Mobile World
Cybersecurity in an IoT and Mobile World
 
Flutter state management from zero to hero
Flutter state management from zero to heroFlutter state management from zero to hero
Flutter state management from zero to hero
 
Flutter state management from zero to hero
Flutter state management from zero to heroFlutter state management from zero to hero
Flutter state management from zero to hero
 
Building your actions for Google Assistant
Building your actions for Google AssistantBuilding your actions for Google Assistant
Building your actions for Google Assistant
 
Building beautiful apps with Google flutter
Building beautiful apps with Google flutterBuilding beautiful apps with Google flutter
Building beautiful apps with Google flutter
 
Building Successful Apps with Google Firebase
Building Successful Apps with Google FirebaseBuilding Successful Apps with Google Firebase
Building Successful Apps with Google Firebase
 

Recently uploaded

Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 

Recently uploaded (20)

Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 

Null safety in dart and flutter , the whole story!

  • 1. Ahmed Abu Eldahab GDE Flutter & Dart @dahabdev Null Safety in Dart and Flutter , The whole Story!
  • 2. Ahmed Abu Eldahab Google Developer Expert in Flutter & Dart Senior Technical Consultant Kortobaa LLC CTO /Dahabdev
  • 5. Tony Hoare Sir Charles Antony Richard Hoare born 11 January 1934) - is a British computer scientist. He developed the sorting algorithm quicksort in 1959–1960.[5] He also developed Hoare logic for verifying program correctness. https://en.wikipedia.org/wiki/Tony_Hoare /DahabDev
  • 6. - In 1960, Hoare left the Soviet Union and began working at Elliott Brothers. - After 9 months of programming he was asked to design a new programming language !! - Most software was still written in machine code. - In the library was a 23-page booklet entitled "Report on the international language ALGOL60" - He used it as a basis for the new language. - In order to implement error messages, an array had a check to verify whether its reference was in the bounds!. - Adding checks to arrays added space and time to the program !. - Then he went and invented the null pointer. Or he either have to check every reference. https://en.wikipedia.org/wiki/Tony_Hoare Tony Hoare in Moscow 1960 /DahabDev
  • 7. Variables String name = ‘Ahmed’; Type Name Value /DahabDev
  • 8. Memory Allocation String name = ‘Ahmed’; NameType Init val Address Value 0012CCGWH80 Ahmed Identifier Memory name /DahabDev
  • 11. Null Pointer/Reference - A null pointer is a pointer that does not point to any memory location. - It represents an invalid memory location . - when a null value is assigned to a pointer then the pointer is considered as null pointer. /DahabDev
  • 12. Null Pointer/Reference Exception (NPE) - Invoking a method from a null object. - Accessing or modifying a null object’s field. - Taking the length of null, as if it were an array. - Accessing or modifying the slots of null object, as if it were an array. /DahabDev
  • 13.
  • 15. Something was called on null /DahabDev
  • 16. Null Pointer Exception (NPE) /DahabDev
  • 17. Tony Hoare https://en.wikipedia.org/wiki/Tony_Hoare I call it my billion-dollar mistake. It was the invention of the null reference in 1965. ... This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years. 2009 /DahabDev
  • 18. Tony Hoare https://en.wikipedia.org/wiki/Tony_Hoare - Null references have historically been a bad idea. - Programming language designers should be responsible for the errors in programs written in that language. - If the billion dollar mistake was the null pointer, the C gets() function is a multi-billion dollar mistake that created the opportunity for malware and viruses to thrive (Buffer overflow) /DahabDev
  • 19.
  • 20. Important Expressions Dynamic Type system Static Type system Null Safety Unsound Null SafetySound Null Safety /DahabDev
  • 22. Dart Null Safety Null safety is the largest change we’ve made to Dart since we replaced the original unsound optional type system with a sound static type system in Dart 2.0. /DahabDev
  • 28. Dart Null safety principles /DahabDev Dart null safety support is based on the following three core design principles: ● Non-nullable by default. Unless you explicitly tell Dart that a variable can be null, it’s considered non-nullable. This default was chosen after research found that non-null was by far the most common choice in APIs. ● Incrementally adoptable. You choose what to migrate to null safety, and when. You can migrate incrementally, mixing null-safe and non-null-safe code in the same project. We provide tools to help you with the migration. ● Fully sound. Dart’s null safety is sound, which enables compiler optimizations. If the type system determines that something isn’t null, then that thing can never be null. Once you migrate your whole project and its dependencies to null safety, you reap the full benefits of soundness —- not only fewer bugs, but smaller binaries and faster execution https://dart.dev/null-safety
  • 29. /DahabDev - All variables are non-nullable by default - If the variable can have the value null, add ? to its type declaration. String? name = null; - If you know that a non-nullable variable will be initialized to a non-null value before it’s used, but the Dart analyzer doesn’t agree, insert late before the variable’s type. late String name; Dart null safety roles https://dart.dev/null-safety
  • 30. /DahabDev - When using a nullable variable or expression, be sure to handle null values. For example, you can use an if statement, the ?? operator, or the ?. operator to handle possible null values. String value = name ?? ''; // '' if it's null; otherwise, the String - If you’re sure that an expression with a nullable type isn’t null, you can add ! to make Dart treat it as non-nullable: String? name = 'Ahmed'; String value = name!; // `name!` is an String. // This throws if name is null. Dart null safety roles https://dart.dev/null-safety
  • 31. Dart null safety roles /DahabDev - Once you opt into null safety, you can’t use the member access operator (.) if the operand might be null. Instead, you can use the null-aware version of that operator (?.): double? d; print(d?.floor()); // Uses `?.` instead of `.` to invoke `floor()`. - If you’re sure that an expression with a nullable type isn’t null, you can add ! to make Dart treat it as non-nullable: String? name = 'Ahmed'; String value = name!; // `name!` is an String. // This throws if name is null. https://dart.dev/null-safety
  • 32. list, set, and map /DahabDev https://dart.dev/null-safety
  • 33. list, set, and map /DahabDev https://dart.dev/null-safety
  • 34. /DahabDev Migrating to null safety steps https://dart.dev/null-safety/migration-guide
  • 35. /DahabDev Migrating to null safety steps https://dart.dev/null-safety/migration-guide
  • 36. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide
  • 37. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide
  • 38. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide
  • 39. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide
  • 40. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide Everything is ok? HIT APPLY MIGRATION BUTTON !
  • 41. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide
  • 42. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide The analyzer can be wrong sometimes !
  • 43. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide
  • 44. /DahabDev How to practice Null safety? https://nullsafety.dartpad.dev
  • 46. Migrating to null safety /DahabDev 1. Wait for the packages that you depend on to migrate. 2. Migrate your package’s code, preferably using the interactive migration tool. 3. Statically analyze your package’s code. 4. Test to make sure your changes work. 5. If the package is already on pub.dev, publish the null-safe version as a prerelease version. https://dart.dev/null-safety
  • 48.
  • 50. Ahmed Abu Eldahab Google Developer Expert in Flutter & Dart Senior Technical Consultant Kortobaa LLC CTO /Dahabdev