Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is "!" in Dart Flutter?

I know ! is used for NOT operation, but i find a code that use ! to fill variable with nullable type variable. When i read some code reference from internet i find this:

 NoteDetailPage(noteId: note.id!)

This is what it look like in NoteDetailPage:

const NoteDetailPage({
    Key? key,
    required this.noteId,
  }) : super(key: key);

note.id is a nullable int type and noteId is in int. If i go noteId: note.id then it will return conversion error error: The argument type 'int?' can't be assigned to the parameter type 'int'., but when i plug !, it doesn’t show any error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

i tried to do a google search, but it says that "!" is for NOT operations, but I don’t think it makes any sense to put NOT operations in that code. Does anyone know the function of "!" on that code?

>Solution :

The name of the sign ! is Bang operator in Dart.

By using ! operator, you are telling the compiler the variable won’t be null.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading