What is the difference between required and @required in flutter 2?

Let's talk about the difference between the @required annotation and the required keyword:

  • @required is just an annotation that allows parsers to let you know that the function is missing a named parameter; so, you can still compile the application and possibly get an exception if this named parameter was not passed.
  • required is an annotation added from Null safety to add null safety: A keyword is now required that must be passed to a named parameter so that it will not allow the compiler to run if this parameter has not been passed . It makes your code more strict and secure.

Considerations

With null security, a named argument with a non-nullable type must either have a default value or be marked with the new required keyword.

When code is called with a value that may be null the required keyword is treated exactly like the @required annotation.
 

- Andrés Cruz

En español

Andrés Cruz

Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz In Udemy

I agree to receive announcements of interest about this Blog.

!Courses from!

10$

On Udemy

There are 3d 02:07!


Udemy

!Courses from!

4$

In Academy

View courses

!Books from!

1$

See the books
¡Become an affiliate on Gumroad!