Flutter: Null Safety (!, ?, ??, late)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
we learn about flutter null safety a variable requires a real value assigning a null value is not allowed by default simply add a question mark so that you can also assign a null value to your variable calling a method or property on a nullable type doesn't work therefore you need to add a question mark or exclamation mark before the dot for a variable that is null the question mark will return a null value as a result and the exclamation mark will throw an exception at runtime that crashes your app on the other hand if the variable has a real value then the methods and properties are executed normally and return their result next converting a nullable type to a not nullable type doesn't work by default since a not nullable type doesn't support potential null values simply add to the right side of the variable an exclamation mark or a default value if the variable is null the exclamation mark will throw an exception and crashes the app the other operation will assign the default value to the variable if the variable was null otherwise if the variable has real value then both operations will assign this value to the variables and finally if you don't want to make your variable nullable because you initialized it already somewhere else then simply add the late keyword before the variable type the late keyword is a promise to that that the variable is later initialized with a real value if you missed to initialize this variable then you didn't fulfill this promise and it will lead to a runtime exception and crashes the app [Music] you
Info
Channel: HeyFlutter․com
Views: 21,994
Rating: undefined out of 5
Keywords: dart, dart null safety, dart null safety operators, flutter, flutter exclamation mark, flutter for beginners, flutter late keyword, flutter late modifier, flutter null safety, flutter null safety exclamation mark, flutter null safety question mark, flutter question mark, flutter question mark after variable, flutter tutorial, intro to null safety, null safety, null safety dart, null safety errors, null safety flutter, null safety in dart
Id: pgBwnMhz5nE
Channel Id: undefined
Length: 1min 41sec (101 seconds)
Published: Wed Mar 16 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.