program to demonstrate null safety
/*
Null safety is a feature in the Dart programming language that helps developers to avoid null errors. 
This feature is called Sound Null Safety in dart.
With dart sound null Safety, you cannot provide a null value by default. 
If you are sure to use it, then you can use ? operator after the type declaration.
*/

void main(){
// Declaring a nullable variable by using ?
String? name;
// Assigning John to name
name = "John";
// Assigning null to name
name = null;
}

________________________________________________________________________________________________________

Another example of null safety

void main() {
  // list of nullable ints
  List<int?> items = [1, 2, null, 4];
  print(items);
}
________________________________________________________________________________________________________

Another example of null safety

// address is a nullable string
void printAddress(String? address) {
  print(address);
}
void main() {
  // Passing null to printAddress
  printAddress(null); // Works
}

________________________________________________________________________________________________________

Define class to null property

class Person {
  String? name;
  Person(this.name);
}

void main() {
  Person person = Person(null); // Works
}

________________________________________________________________________________________________________

Nullable class properties

  class Profile {
  String? name;
  String? bio;

  Profile(this.name, this.bio);

  void printProfile() {
    print("Name: ${name ?? "Unknown"}");
    print("Bio: ${bio ?? "None provided"}");
  }
}

void main() {
  // Create a profile with a name and bio
  Profile profile1 = Profile("John", "Software engineer and avid reader");
  profile1.printProfile();

  // Create a profile with only a name
  Profile profile2 = Profile("Jane", null);
  profile2.printProfile();

  // Create a profile with only a bio
  Profile profile3 = Profile(null, "Loves to travel and try new foods");
  profile3.printProfile();

  // Create a profile with no name or bio
  Profile profile4 = Profile(null, null);
  profile4.printProfile();
}

________________________________________________________________________________________________________

