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

- Andrés Cruz

En español
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.


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

Desarrollo con Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz en Udemy

Acepto recibir anuncios de interes sobre este Blog.