Dart : Null

Dart : Null

ยท

1 min read

  • Dart provide many unique function compare to other language , therefore dart is popular language among the developer.

  • One of the unique function of dart in Unsafety, which means dart also support the Null value in variable.

  • Null safety make code safer and run faster.

  • in null safety we use two symbol " ? ! " .

  • Where " ? " indicate that we can assign the variable to null.

  • Here, I am providing the example of Null safety.

        void main()
      {
       int? x;
       print(x); // null
      }
    
      void main()
      {
       int? x;
       print(x);
       int y =x!;
      }
    
    • In this we get the error like " Null check operator used on a null value " due to here x is nullable type where is notnullable type but we force to run this program by putting " ! ".
ย